일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
- hash table
- 쉬움
- binary tree
- Medium
- list
- Python
- recursive
- linked list
- 재귀
- binary search
- 미디움
- 문자열
- backtracking
- Binary
- DP
- tree
- dfs
- leetcode
- matrix
- Array
- two pointers
- HashTable
- easy
- 중간
- math
- 이진트리
- 리트코드
- sorting
- Depth-first Search
- string
- Today
- Total
목록Medium (49)
부부의 코딩 성장 일기
1. 문제 링크 https://leetcode.com/problems/3sum/ 3Sum - LeetCode Can you solve this real interview question? 3Sum - Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0. Notice that the solution set must not contain du leetcode.com 2. 문제 설명 주어진 리스트 nums와 서로 다른 인덱스 i, j, k에 대하여 nums[i]+nums[j]+nums[..
1. 문제 링크 https://leetcode.com/problems/integer-to-roman/submissions/ 2. 문제 설명 우리가 쓰는 정수가 주어지면 Roman 숫자로 바꾸어 return 하는 문제 아래의 기호를 이용함 I: 1 V: 5 X: 10 L: 50 L: 100 D: 500 M: 1000 이 때, I는 V,X 앞에 쓰여서 4,9를 나타냄 X는 L,C 앞에 쓰여서 40,90을 나타냄 C는 D,M 앞에 쓰여서 400,900을 나타냄 예시) 3 → III, 58 → LVIII, 1994 → MCMXCIV 3. 처음 풀이 딱히 특별한 알고리즘이 없을 것 같아서, 정수에 매칭되는 로마 문자에 대한 dictionary를 만들어두고, num 이 특정 숫자 이상이면, 그 숫자에 대한 로마 문..
1. 문제 링크 LeetCode - The World's Leading Online Programming Learning Platform Container With Most Water - LeetCode Can you solve this real interview question? Container With Most Water - You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, height[i]). Find two lines that toget leetcode.com 2. 문제 설명 리트 코드..
1. 문제 링크 https://leetcode.com/problems/string-to-integer-atoi/ 2. 문제 설명 주어진 문자열을 숫자로 바꾸는 것 규칙 처음 나오는 공백 ''은 무시 그러다가 처음에 부호('+', '-')가 나오면 이를 최종 결과에 반영 그 외 수가 아닌 문자가 나오면 멈춤 (기본값은 0, 그 전에 수가 나와서 반영되었다면 그 값) 수가 나오기 시작했으면 그 이후에 수가 아닌 것이 나오면 멈춤 마지막으로 32bit 넘어가면, 내리거나(너무 큰 수), 올려서(너무 작은 수) 반환 예시1) "42" → 42 예시2) " -42" → -42 (공백 무시) 예시3) "4193 with words" → 4193 (수 뒤에 수 아닌 것 나오면 stop) 예시4) "-1123u3761..
1. 문제 링크 https://leetcode.com/problems/reverse-integer/ Reverse Integer - LeetCode Can you solve this real interview question? Reverse Integer - Given a signed 32-bit integer x, return x with its digits reversed. If reversing x causes the value to go outside the signed 32-bit integer range [-231, 231 - 1], then return 0. Assume the envir leetcode.com 2. 문제 설명 부호가 있는 32bit 정수가 주어졌을 때, 앞뒤 순서를 바꾸어 ..
1. 문제 링크 https://leetcode.com/problems/zigzag-conversion/ 2. 문제 설명 문자열과 줄 개수가 주어졌을 때, 이를 ↓↗↓↗ 로 반복 배열 한 후, 위에서 아래로 이어붙여서 반환 예시) str= "PAYPALISHIRING", numRows = 3이 주어지면 P A H N A P L S I I G Y I R 로 배열한 후, 위에서 아래로 이어붙여서 "PAHNAPLSIIGYIR"를 반환 3. 처음 풀이 46ms(97.08%), 16.48mb(36.12%) 문제 이름대로 지그재그 움직이는 아이디어 현재 가로 줄이 몇 번째인지 나타내는 변수 position과 위로 갈지 아래로 갈지 방향을 나타내는 변수 direction에 0, 1을 초기 할당함 현재 위치한 가로 줄에..
1. 문제 링크 https://leetcode.com/problems/longest-palindromic-substring/ str: result_len = 0 #대칭인 문자열의 길이 result ='' #대칭인 문자열 if len(s)= 0 and j < n and s[i] == s[j]: i, j = i - 1, j + 1 return s[i + 1:j] for k in range(n): ans = max(helper(k, k), helper(k, k + 1), ans, key=len) # helper(k, k) for odd length, helper(k, k+1) for even length return ans 5. 배운 점 확실히 난이도가 medium인 문제들은 단순히 이중 삼중 포문으로는 ti..
1. 문제 링크 Longest Substring Without Repeating Characters - LeetCode 2. 문제 설명 주어진 문자열에 포함된 문자열 중 중복된 문자가 없는 것 중 길이의 최댓값을 반환 예시) s = "abcabcbb"이면 "abc"가 가장 길기 때문에 3, s = "bbbbb"이면 "b"가 가장 길기 때문에 1, s = "pwwkew"이면 "wke"가 가장 길기 때문에 3 3. 처음 풀이 왼쪽을 고정 후 오른쪽은 한칸씩 이동하며 새로운 문자가 등장하면 현재 문자열을 temp에 저장 이미 나온 문자가 등장하면 왼쪽을 한칸 이동하고 temp를 비운 후 반복 temp를 비울 때 마다 이전까지 구한 최댓값 result와 현재 문자열 길이 중 최댓값으로 result 업데이트 매번..