Zero to Hero
article thumbnail
384. Shuffle an Array
Algorithm 2021. 6. 14. 21:42

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..

article thumbnail
454. 4Sum II
Algorithm 2021. 6. 13. 14:10

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 ..

article thumbnail
341. Flatten Nested List Iterator
Algorithm 2021. 6. 13. 00:21

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: # """ ..

article thumbnail
172. Factorial Trailing Zeroes
Algorithm 2021. 6. 10. 17:53

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..

article thumbnail
125. Valid Palindrome
Algorithm 2021. 6. 8. 11:20

Valid Palindrome - 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. isalnum() class Solution: def isPalindrome(self, s: str) -> bool: stack = [] for char in s: if char.isalnum(): stack.append(char.lower()) if len(stack) % 2 == 1: return stack[:len(stack) // 2] == stack[len(stack)..

article thumbnail
118. Pascal's Triangle
Algorithm 2021. 6. 7. 21:37

Pascal's Triangle - 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 generate(self, numRows: int) -> List[List[int]]: answer = [[1]] if numRows == 1: return answer elif numRows == 2: answer.append([1, 1]) return answer else: answer.appe..