Palindrome Partitioning - 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 문자열이 입력된다. 입력된 문자열의 연속된 부분 문자열이 모두 Palindrome(회문, 앞에서 읽어도, 뒤에서 읽어도 같은 문자열)이 되게 하는 그 결과 목록을 반환하는 문제다. 1. DP + DFS from typing import * class Solution: def partition(self, s: str) -> List[List[str]]: answers = ..
Construct Binary Tree from Preorder and Inorder Traversal - 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 이진트리의 PreOrder 순회 결과와 InOrder 순회 결과를 입력하면 이진트리를 복원해서 반환하는 문제다. 1. 4개의 index 값을 이용한 DFS from typing import * class Solution: def buildTree(self, preorder: List[int], inorder: ..
Shuffle 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 class Solution: def __init__(self, nums: List[int]): def reset(self) -> List[int]: """ Resets the array to its original configuration and return it. """ def shuffle(self) -> List[int]: """ Returns a random shuffling..
4Sum 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. 틀림 from typing import * class Solution: def fourSumCount(self, nums1: List[int], nums2: List[int], nums3: List[int], nums4: List[int]) -> int: set1, set2 = set(), set() for num1 in nums1: for num2 in nums2: set1.add(num1 ..
Flatten Nested List Iterator - 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 # """ # This is the interface that allows for creating nested lists. # You should not implement it, or speculate about its implementation # """ #class NestedInteger: # def isInteger(self) -> bool: # """ ..
Factorial Trailing Zeroes - 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 trailingZeroes(self, n: int) -> int: return n // 5 N이 주어지고 N! 의 0의 개수를 반환하는 문제다. 처음에는 DP 인가라고 생각을 했다가 좀 더 쉽게 생각할 수 있는 문제인 것 같았다. 0이 만들어지려면 10이 곱해져야 한다. 그리고 10은 2와 5의 곱이다. 즉 2와 5..