본문 바로가기

분류 전체보기

(248)
21/07/29 알고리즘 스터디 정리 (작성중) string에도 push_back쓸수있다 int a[100] a.begin(), a.end()먹나? reverse(a, a+len(a))하면 먹는다 iterator는 포인터->주소를 가리킨다 sorted는 항상 list반환 reversed는 reversed객체 반환 리스트빼기 대체->어케? 리스트 컴프리헨션으로 not in 우로 list + list해야 붙음 .append로 해야 is alpha 전체가 다 alpha여야 True &참조자->call by value pair면 second까지만 가능? pair앞에 식별자만 넣어도 make_pair substr이 문자열을 거기부터 끝까지->파이썬 슬라이싱처럼 d 3이면 공백나옴? split(" ")랑 split()차이 keys() 객체로 나옴
[문자열 조작] 06 가장 긴 팰린드롬 부분 문자열(Longest Palindromic Substring) ✔ https://leetcode.com/problems/longest-palindromic-substring/ Longest Palindromic Substring - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 브루트포스로 모든 substring에 대해 탐색을 하게 되면 코드가 다음과 같습니다. 모든 substring을 탐색하고 안에서는 O(1)이라고 생각하여 코드를 작성했는데 now_s == now_s[::-1]에서 뒤집고 비교하는 과정이 O(N)이므로 전체..
[문자열 조작] 05 그룹 애너그램(Group Anagrams) https://leetcode.com/problems/group-anagrams/ Group Anagrams - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 문자열 배열을 받아 애너그램 단위로 그룹핑하는 문제입니다. 애너그램이란 어떤 문자열의 문자를 재배열하여 다른 문자열과 같아지는 것입니다. 문자열의 구성 알파벳을 기준으로 그룹핑이 필요하므로, 구성 알파벳을 뽑아야 합니다. 처음 문제를 풀 때, set()을 통해 구성 알파벳을 구하고 이를 key값으로 이용하..
[문자열 조작] 04 가장 흔한 단어(Most Common Word) https://leetcode.com/problems/most-common-word/ Most Common Word - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 금지된 단어를 제외한 가장 흔하게 등장하는 단어를 출력하는 문제입니다. 이때, 대소문자 구분을 하지 않으며 구두점(마침표, 쉼표 등)은 무시합니다. 입력값에 대소문자가 섞여있고, 쉽표 등 구두점이 존재하므로 입력값에 대한 전처리 작업이 필요합니다. 정규식을 통해 편리하게 처리할 수 있습니다. cla..
[문자열 조작] 03 로그 파일 재정렬(Reorder Data in Log Files) https://leetcode.com/problems/reorder-data-in-log-files/ Reorder Data in Log Files - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 주어지는 조건대로 정렬을 하는 문제입니다. 숫자로그는 입력 순서대로이므로 문자로그와 숫자로그를 구분하고, 숫자로그는 나중에 그대로 이어 붙이면 됩니다. 이때, 문자로그는 문자로그 내에서 정렬을 해주어야 하는데, content로 1차 비교, identifier로 2차 ..
[문자열 조작] 02 문자열 뒤집기(Reverse String) https://leetcode.com/problems/reverse-string/ Reverse String - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 리스트를 뒤집는 문제입니다. 이때, 리턴 없이 주어지는 리스트 내부를 직접 조작해야 합니다. 맨 처음 시도한 코드는 다음과 같습니다. class Solution: def reverseString(self, s: List[str]) -> None: s=s[::-1] 기존 리스트가 뒤집힌 리스트의 data가 ..
[문자열 조작] 01 유효한 팰린드롬(Valid Palindrome) https://leetcode.com/problems/valid-palindrome/ Valid Palindrome - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 주어지는 문자열이 팰린드롬(뒤집어도 같은 문자열)인지 확인하는 문제입니다. 이때, 제약조건으로 대소문자를 구분하지 않으며, 영문자와 숫자만을 대상으로 합니다. 먼저 대소문자 구분을 없애고, 영문자와 숫자만을 보기 위한 전처리가 필요합니다. 그 이후, 전처리된 문자열을 뒤집어서 같은지 확인합니다. 처..
[Python]정수, 진법, 문자열, 배열 다음 블로그의 내용을 보고 적은 내용입니다. https://covenant.tistory.com/142 🔥 용감하게 시작하는 코딩테스트 2편 0. 무엇을 공부할까요? 파이썬의 정수, 문자열, 배열 자료형에 대해서 살펴볼 것입니다. 파이썬 기본 문법책을 펴보면 가장 앞 단원에 나오기에 자신이 있을텐데요. 코딩테스트를 준비하는 관점 covenant.tistory.com 1. 정수 1-1. 최대, 최소 import sys ans = sys.maxsize for num in arr: if ans > num: ans = num print(ans) 2. 진법 2-1. 10진수 → 2, 8, 16진수 변환 >>> bin(42) >'0b101010' >>> oct(42) >'0o52' >>> hex(42) >'0x2a..