일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 재귀
- string
- 중간
- Array
- 쉬움
- math
- backtracking
- easy
- list
- Binary
- Medium
- 이진트리
- HashTable
- Python
- recursive
- 문자열
- Depth-first Search
- 리트코드
- dfs
- two pointers
- 미디움
- DP
- hash table
- sorting
- tree
- leetcode
- binary tree
- matrix
- linked list
- binary search
- Today
- Total
목록leetcode (78)
부부의 코딩 성장 일기
1. 문제 링크 https://leetcode.com/problems/merge-sorted-array/ 2. 문제 설명 오름차순 정수로 구성된 두 array nums1, nums2와, 각 array의 개수를 m,n이라고 할 때, nums1, nums2를 오름차순 순서로 merge한 list를 반환 전제조건 "in-place" return하는 list는 nums1에 store해야 하며, 결과적으로 nums의 길이는 m+n이 됨 예시1) nums1 = [1,2,3,0,0,0] m=3, nums2 = [2,5,6] n= 3 → [1,2,2,3,5,6] 반환 예시2) nums1 = [1] m=1, nums2 = [] n= 0 → [1] 반환 3. 처음 풀이 nums1의 m+1~m+n 자리에 nums2 elem..
1. 문제 링크 https://leetcode.com/problems/climbing-stairs/ 2. 문제 설명 계단을 n steps에 거쳐 올라가며, 한번에 1 or 2 steps 씩밖에 오르지 못할 때, n개 계단을 오르는 방법의 수를 반환 예시1) n=2 이면 1step + 1step / 2steps 이렇게 두가지 방법이 가능하므로 2를 반환 예시2) n=3 이면 1step + 1step + 1step / 1step + 2steps / 2steps + 1steps 세 방법이 가능하므로 3을 반환 → 규칙을 찾아야하는 문제 3. 처음 풀이 2~7 steps 까지를 나열해보며 규칙을 찾았다. (물론 더 쉬운 규칙이 있었음) 3 step = 1 step으로 3번 움직이거나, 2step과 1step으로..
1. 문제 링크 https://leetcode.com/problems/add-binary/ 2. 문제 설명 이진법으로 구성된 두개의 문자열 a,b가 주어졌을 때, 두 개의 합을 이진법으로 반환 예시) a= "11", b= "1"이면 십진법으로 3+1= 4이고, 이를 다시 이진법으로 반환한 "100"을 반환 3. 처음 풀이 만약 두 문자열이 0이면 0을 반환, 두 문자열을 더한 값을 십진법으로 반환하고 → 다시 이진법으로 변환하는 식으로 풀이 "11"과 "1"을 더한 "12"를 십진법으로 변환하면, 2*1 + 1*2^1 = 4 4를 계속 2로 나누면서 이진법으로 변환 result = '' (sum_num = 4) result = '0' (sum_num = 2) result = '00' (sum_num = ..
1. 문제 링크 Plus One - LeetCode Plus One - LeetCode Can you solve this real interview question? Plus One - You are given a large integer represented as an integer array digits, where each digits[i] is the ith digit of the integer. The digits are ordered from most significant to least significant in left-to- leetcode.com 2. 문제 설명 리스트 [1, 2, 3]가 주어지면 123에 1을 더한 124를 리스트로 바꾸어 [1, 2, 4]를 반환 3. 처음 풀이 주어..
1. 문제 링크 https://leetcode.com/problems/length-of-last-word/ 2. 문제 설명 단어와 공백으로 구성된 문자열 s가 주어졌을 때, 가장 마지막 단어의 길이를 반환 예시) s = "Hello World", output: 5 (마지막 단어인 "World"의 길이 5 반환) 3. 처음 풀이 문자열에 대한 관련 함수를 이미 알고 있어서, 간단하게 해결. s의 양쪽 공백을 없애고, ' ' 기준 split을 한 후, 마지막 element의 lenght를 반환 class Solution: def lengthOfLastWord(self, s: str) -> int: return len(s.strip().split(' ')[-1]) # 양 쪽 공백을 없애고, ' '기준으로 s..
1. 문제 링크 Search Insert Position - LeetCode Search Insert Position - LeetCode Can you solve this real interview question? Search Insert Position - Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You must w leetcode.com 2. 문제 설명 정수가 오름차순으로 정렬된 리스트와 하나의 정수가 주어졌을 때 정수를 리스트에..
1. 문제 링크 https://leetcode.com/problems/remove-duplicates-from-sorted-array/ 2. 문제 설명 이번엔 좋아요(13K)보다 싫어요(17.2K)가 더 많지만 그럼에도 상위에 있는 문제 오름차순으로 sort된 nums라는 배열이 있을 때, 중복이 없도록 array를 쌓고, unique 배열의 가장 마지막 index를 반환. 간단해보이지만, 전제조건이 "in-place"로, 기존의 데이터 구조를 변경하지 않고 정렬 또는 변환 작업을 수행해야 함 예시1) nums = [1,1,2] 일 때, nums = [1,2,_]로 변환하고, 2의 index인 1를 반환 예시2) nums = [0,0,1,1,1,2,2,2,3,3,4] 일 때, nums = [0,1,2,3..
1. 문제 링크 https://leetcode.com/problems/find-the-index-of-the-first-occurrence-in-a-string/ Find the Index of the First Occurrence in a String - LeetCode Can you solve this real interview question? Find the Index of the First Occurrence in a String - Given two strings needle and haystack, return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. Exam..