Algorithm
-
[Leetcode] 1. Two Sum 문제 풀이Algorithm/문제풀이 2021. 10. 8. 15:08
https://leetcode.com/problems/two-sum/ Two Sum - 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 문제 내용 2개를 더해서 target 되는 index를 구하는 문제 Example 1: Input: nums = [2,7,11,15], target = 9 Output: [0,1] Output: Because nums[0] + nums[1] == 9, we return [0, 1]. 문제 풀이 일반적으로 하면 O(n^2) 만큼 걸..
-
[Leetcode] 208. Implement Trie (Prefix Tree) 문제 풀이Algorithm/문제풀이 2021. 10. 8. 10:14
https://leetcode.com/problems/implement-trie-prefix-tree/ Implement Trie (Prefix Tree) - 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 문제 내용 Trie 구현 Example 1: Input ["Trie", "insert", "search", "search", "startsWith", "insert", "search"] [[], ["apple"], ["apple"], ["app"], ["app..
-
[Leetcode] 79. Word Search 문제 풀이Algorithm/문제풀이 2021. 10. 7. 11:34
https://leetcode.com/problems/word-search/ Word Search - 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 문제 내용 문자로 구성된 board가 있는데 찾고자 하는 단어가 board에서 찾을 수 있는 지 검사하는 문제 Example 1: Input: board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "ABCCED" Output: true 문제 ..
-
[Leetcode] 442. Find All Duplicates in an Array 문제풀이Algorithm/문제풀이 2021. 10. 6. 22:57
https://leetcode.com/problems/find-all-duplicates-in-an-array/ Find All Duplicates in an Array - 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 문제 내용 배열 중에 같은 수 찾기 문제 요소는 1개 또는 2개로 이루어져있다. Example 1: Input: nums = [4,3,2,7,8,2,3,1] Output: [2,3] 문제 풀이 시간복잡도 O(n), 공간복잡도 O(1) 만에 풀 수..
-
[Leetcode] 217. Contains Duplicate 문제풀이Algorithm/문제풀이 2021. 10. 5. 13:21
https://leetcode.com/problems/contains-duplicate/ Contains Duplicate - 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 문제 내용 배열에서 중복된 값이 있는지 검사하는 문제 Example 1: Input: nums = [1,2,3,1] Output: true 문제 풀이 hash를 이용해서 값을 메모해놓고 hash값이 있으면 true를 반환하면 된다. 그런데 이상하게 sort 하고 검사하는것보다 속도가 늦게 나..
-
[Leetcode] 53. Maximum Subarray 문제풀이Algorithm/문제풀이 2021. 10. 5. 13:16
https://leetcode.com/problems/maximum-subarray/ Maximum Subarray - 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 문제 내용 연속된 부분 집합의 합이 최대인 값을 구하는 문제 Example 1: Input: nums = [-2,1,-3,4,-1,2,1,-5,4] Output: 6 Explanation: [4,-1,2,1] has the largest sum = 6. 문제 풀이 연속된 값만 구하면 된다. 연속해서..
-
[Leetcode] 463. Island Perimeter 문제풀이Algorithm/문제풀이 2021. 10. 4. 16:56
https://leetcode.com/problems/island-perimeter/ Island Perimeter - 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 문제 내용 섬이 하나가 주어지는데 섬의 테두리 길이를 구하는 문제 Example 1: Input: grid = [[0,1,0,0],[1,1,1,0],[0,1,0,0],[1,1,0,0]] Output: 16 Explanation: The perimeter is the 16 yellow stripes ..
-
[Leetcode] 322. Coin Change 문제풀이Algorithm/문제풀이 2021. 10. 2. 14:26
https://leetcode.com/problems/coin-change/ Coin Change - 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 문제 내용 배열에 있는 숫자를 조합해서 amount를 만드는데 최소가 되는 배열 크기 구하기 배열에 있는 숫자는 중복해서 사용가능하다 Example 1: Input: coins = [1,2,5], amount = 11 Output: 3 Explanation: 11 = 5 + 5 + 1 문제 풀이 DP를 이용해서 풀었..