Zero to Hero
article thumbnail
134. Gas Station
Algorithm 2021. 10. 24. 21:35

Gas Station - 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 양의 정수로 이루어진 gas, cost 배열이 주어진다. 두 배열의 길이는 같다. 임의의 index에서 시작해 도착하는 index의 gas [index]를 얻고, index+1로 이동할 때 cost [index] 만큼 잃는다고 가정하자. 배열에 임의의 인덱스 i에서 (i+1, i+2.... 0, 1, 2,..... i-2, i-1, i) 순서로 순회하는 것이 가능한 i를 반환하는 문제다. 조..

article thumbnail
395. Longest Substring with At Least K Repeating Characters
Algorithm 2021. 10. 23. 16:04

Longest Substring with At Least K Repeating Characters - 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 문자열 s와 양의 정수 k가 주어진다. s의 부분 문자열을 구성하는 문자의 출현 빈도수가 k보다 같거나 큰 조건을 만족하는 부분 문자열의 최대 길이를 반환하는 문제다. 예시 Input: s = "aaabb", k = 3 Output: 3 Explanation: The longest substring is "aaa",..

article thumbnail
55. Jump Game
Algorithm 2021. 10. 22. 22:12

Jump Game - 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 0과 같거나 큰 정수로 구성된 1차원 배열이 주어진다. 0번 인덱스에서 시작해서 해당 인덱스가 가리키는 값만큼 인덱스를 이동할 수 있을 때 정수 배열의 마지막 인덱스로 이동이 가능한지를 판단하는 문제다. 예시 Input: nums = [2,3,1,1,4] Output: true Explanation: Jump 1 step from index 0 to 1, then 3 steps to the la..

article thumbnail
213. House Robber II
Algorithm 2021. 10. 21. 12:56

House Robber II - 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차원 배열이 주어진다. 도둑은 배열을 방문하면서 방문한 곳에 해당하는 정수만큼 돈을 훔칠 수 있다. 단 연속된 배열을 방문할 순 없고, 최소 한 칸 이상 건너서 훔칠 수 있다. 도둑이 훔칠 수 있는 최댓값을 반환하는 문제다. 단 주의할 점이 있다면 1차원 배열이 주어지지만 이 배열이 원형으로 되어있어 0번 인덱스와 N-1 인덱스는 인접하고 있다는 조건이 추가되었..

article thumbnail
79. Word Search
Algorithm 2021. 10. 20. 15:05

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 영어 대문자로 구성된 2차원 배열이 주어진다. 임의의 위치에서 시작해 네 방향으로 이동하면서 주어진 문자열을 만들 수 있는지를 판단하는 문제다. 예시 Input: board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "ABCCED" Output: true 여기서 방문한 격자를 중복해서 선택할 순 없다. 그러므로 위 예..

article thumbnail
572. Subtree of Another Tree
Algorithm 2021. 10. 16. 20:24

Subtree of Another 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 트리 a, b가 주어진다. 트리 b가 트리 a에 포함되는지를 판단해 반환하는 문제다. 즉 트리 b가 트리 a와 같거나 혹은 트리 a의 서브 트리인지를 반환하면 된다. 접근법 중위, 후위, 전위 순회로 트리 2개를 탐색하고, 탐색 순서를 문자열로 변환해 트리 a의 탐색 순서 문자열에 트리 b의 탐색 순서 문자열이 존재하는지 판단하는 것으로 접근했다. 그런데 이것으론 예외를..