목록lev2 (14)
취미가 좋다
https://leetcode.com/problems/product-of-array-except-self/ Product of Array Except Self - 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 Solution class Solution: def productExceptSelf(self, nums): if nums.count(0) > 1: return [0]*len(nums) idx = -1 total = 1 for i, n in enumerate..
https://leetcode.com/problems/invert-binary-tree/ Invert Binary 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 Solution from collections import deque class Solution: def invertTree(self, root: Optional[TreeNode]) -> Optional[TreeNode]: if not root: return root d = deque() d..
https://atcoder.jp/contests/abc215/tasks/abc215_c C - One More aab aba baa AtCoder is a programming contest site for anyone from beginners to experts. We hold weekly programming contests online. atcoder.jp Solution from itertools import permutations s, k = input().split(' ') a = set([]) for i in permutations(s, len(s)): a.add(i) a = list(a) a.sort() k = int(k) - 1 print(''.join(a[k])) 문자열 s와 순서 ..
https://leetcode.com/problems/number-of-islands/ Number of Islands - 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 Solution class Solution: def __init__(self): self.m = 0 self.n = 0 self.grid = [] self.visit = [] def numIslands(self, grid): self.m = len(grid) self.n = len(grid[0]..
https://leetcode.com/problems/binary-tree-right-side-view/ Binary Tree Right Side View - 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 Solution # Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None, right=None): # self.val = val # self.left ..
https://leetcode.com/problems/house-robber/ House Robber - 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 Solution class Solution: def rob(self, nums): if len(nums) < 2: return nums[0] dp = [] dp.append(nums[0]) dp.append(max(nums[0], nums[1])) for i in range(2, len(nums)): dp.app..