LeetCode Problems6

😍 LeetCode Easy Collections III - 6 Problems 0231. Power of Two / 0118. Pascal's Triangleclass Solution: def isPowerOfTwo(self, n: int) -> bool: if n 😍 0231) 큰 problem을 2로 계속 나누며 sub-problem으로 잘게 쪼개며 계속 문제를 풀어나가는 방식은 Recursion을 사용해야 함을 직관적으로 알 수 있다. 먼저 n == 1 / n%2 == 1 base case를 생각하고 / 그렇지 않다면 pot(n//2)로 잘게 쪼개어 문제를 풀어가면 OKclass Solution: def generate(self, numRows: int) -> List[List[int]]: ans = [[1]] .. LeetCode Problems/Easy 2025. 1. 29.
🧑🏻‍💻 LeetCode Medium Collections 3 - 19 Problems 0003. Longest Substring Without Repeating Characters / 0221. Maximal Square#---------------- (1)class Solution: def lengthOfLongestSubstring(self, s: str) -> int: ans = 0 hashmap = dict() for i in range(len(s)): if s[i] in hashmap.keys(): needs_to_be_deleted_keys = set() for key in hashmap: if hashmap[key] int: .. LeetCode Problems/Medium 2024. 12. 9.
🧑🏻‍💻 LeetCode Medium Collections 2 - 20 Problems 0054. Spiral Matrix / 0739. Daily Temperaturesclass Solution: def spiralOrder(self, matrix: List[List[int]]) -> List[int]: e,s,w,n = [0,1], [1,0], [0,-1], [-1,0] output = [] rows, cols = len(matrix), len(matrix[0]) visited = [[False] * cols for _ in range(rows)] cnt = 0 x, y = 0,0 dirs = [e,s,w,n] dir_i = 0 while True: .. LeetCode Problems/Medium 2024. 10. 31.
🧑🏻‍💻 LeetCode Medium Collections 1 - 20 Problems 0300. Longest Increasing Subsequence / 0053. Maximum Subarrayclass Solution: def lengthOfLIS(self, nums: List[int]) -> int: length = len(nums) dp = [1]*length for x in range(1,length): for y in range(0,x): if nums[y] class Solution: def maxSubArray(self, nums: List[int]) -> int: ans,curmax=-10001,0 for i in range(len(nums)): .. LeetCode Problems/Medium 2024. 9. 9.
😍 LeetCode Easy Collections II - 20 Problems 0283. Move Zeroes / 0344. Reverse Stringclass Solution: def moveZeroes(self, nums: List[int]) -> None: """ Do not return anything, modify nums in-place instead. """ length=len(nums) if length != 1: first_encountered = False for x in range(length-1): if nums[x] == 0: if not first_encountered: .. LeetCode Problems/Easy 2024. 9. 2.
😊 LeetCode Easy Collections I - 20 Problems 0001. Two Sum / 0268. Missing Numberclass Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: dct = dict() for i in range(len(nums)): dct[nums[i]] = i for i in range(len(nums)): if (target-nums[i]) in dct: if i!=dct[target-nums[i]]: return [i,dct[target-nums[i]]]class Solution: def missingNumber.. LeetCode Problems/Easy 2024. 8. 5.