Zero to Hero
article thumbnail
72. Edit Distance
Algorithm 2021. 11. 23. 21:43

Edit Distance - 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. 편집 거리 알고리즘 class Solution: def minDistance(self, word1: str, word2: str) -> int: len1, len2 = len(word1), len(word2) board = [[0] * (len2 + 1) for _ in range(len1 + 1)] for i in range(len(..

article thumbnail
51. N-Queens
Algorithm 2021. 11. 19. 00:08

N-Queens - 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 설명할 필요 없는 N-Queens 문제를 구현해보자. Input: n = 4 Output: [[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]] Explanation: There exist two distinct solutions to the 4-queens puzzle as shown above 1. DFS, 백트래킹 from typing..

article thumbnail
18. 4Sum
Algorithm 2021. 11. 16. 11:07

4Sum - 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 정수 배열이 주어진다. 4개의 정수를 골라 합이 target이 되는 조합 목록을 반환하는 문제다. 단 고른 4개의 정수는 인덱스 값이 모두 달라야 하고, 조합 목록에 중복되는 조합은 제거 후 반환해야 한다. 접근법 pointer를 이용해 3 Sum 까지는 구해봤으니 4 Sum도 동일하게 구할 수 있을 것이다. 단 3 Sum은 1중 for문 안에서 pointer를 조작했으니 4 Sum은 2중 for문 안에..

article thumbnail
404. Sum of Left Leaves
Algorithm 2021. 11. 11. 12:03

Sum of Left Leaves - 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 이진트리의 root가 주어진다. 주어진 트리의 왼쪽 자식 노드의 값의 합을 반환하는 문제다. 예시 Input: root = [3,9,20,null,null,15,7] Output: 24 Explanation: There are two left leaves in the binary tree, with values 9 and 15 respectively. 추가로 왼쪽 자식 노드의 값..

article thumbnail
392. Is Subsequence
Algorithm 2021. 11. 9. 12:08

Is Subsequence - 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가 문자열 t의 최장 공통부분 문자열인지 찾는 문제다. 관련 개념을 가장 잘 설명한 블로그 링크. [알고리즘] 그림으로 알아보는 LCS 알고리즘 - Longest Common Substring와 Longest Common Subsequence LCS는 주로 최장 공통 부분수열(Longest Common Subsequence)을 말합니다만, 최장 공통 문자열(Longest Com..

article thumbnail
16. 3Sum Closest
Algorithm 2021. 11. 2. 11:46

3Sum Closest - 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 정수가 담긴 배열 nums, 특정한 정수 target이 주어진다. nums의 정수 3개를 골라서 더한 합이 target과 가장 가깝게 되는 정수 3개의 합을 반환하는 문제다. 예시 Input: nums = [-1,2,1,-4], target = 1 Output: 2 Explanation: The sum that is closest to the target is 2. (-1 + 2 + 1 =..