LeetCode342 leetcode 1084. Sales Analysis III 1 2 3 4 5 6 7 8 # Write your MySQL query statement below select p.product_id, p.product_name from Sales s left join Product p on p.product_id = s.product_id group by s.product_id having min(s.sale_date)>='2019-01-01' and max(s.sale_date) 2022. 7. 18. leetcode 607. Sales Person 1 2 3 4 5 6 7 8 9 10 # Write your MySQL query statement below select s.name from SalesPerson s where s.name not in ( select s.name from orders o left join company c on o.com_id=c.com_id left join SalesPerson s on o.sales_id =s.sales_id where c.name ='RED' ) Colored by Color Scripter cs 2022. 7. 18. leetcode 1527. Patients With a Condition 1 2 3 4 5 6 # Write your MySQL query statement below select patient_id, patient_name, conditions from Patients where conditions like 'DIAB1%' or conditions like '% DIAB1%' cs 2022. 7. 18. leetcode 1729. Find Followers Count 1 2 3 4 5 # Write your MySQL query statement below select user_id, count(follower_id) as followers_count from Followers group by user_id order by user_id Colored by Color Scripter cs 2022. 7. 18. leetcode 2022. Convert 1D Array Into 2D Array 1 2 3 4 5 6 7 8 9 10 11 12 13 class Solution: def construct2DArray(self, original: List[int], m: int, n: int) -> List[List[int]]: output=[] n_original=len(original) if n_original/m != n : return output else : for i in range(m): tmp_list=[] for j in range(n): tmp_list.append(original[n*i+j]) output.append(tmp_list) return output Colored by Color Scripter cs 2022. 7. 11. leetcode 2215. Find the Difference of Two Arrays 1 2 3 4 5 6 7 8 9 10 11 12 13 14 pythoclass Solution: def findDifference(self, nums1: List[int], nums2: List[int]) -> List[List[int]]: ans1=[] ans2=[] ans_list=[] for i in nums1 : if i not in nums2: ans1.append(i) for i in nums2 : if i not in nums1: ans2.append(i) ans_list.append(list(set(ans1))) ans_list.append(list(set(ans2))) return ans_list Colored by Color Scripter cs 2022. 7. 8. leetcode 2303. Calculate Amount Paid in Taxes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 class Solution: def calculateTax(self, brackets: List[List[int]], income: int) -> float: upper= min(brackets[0][0],income) rate=brackets[0][1] answer = upper * rate / 100 income-=upper for i in range(1,len(brackets)): if income 2022. 7. 7. leetcode 1945. Sum of Digits of String After Convert 1 2 3 4 5 6 7 8 9 10 11 12 13 class Solution: def getLucky(self, s: str, k: int) -> int: str_num='' for i in s: str_num+=str(ord(i)-96) int_num=0 for _ in range(k): for i in str_num: int_num+=int(i) str_num=str(int_num) int_num=0 return(int(str_num)) cs 2022. 7. 7. leetcode 2236. Root Equals Sum of Children 1 2 3 4 5 6 7 8 9 10 11 12 # Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None, right=None): # self.val = val # self.left = left # self.right = right class Solution: def checkTree(self, root: Optional[TreeNode]) -> bool: if root.val == root.left.val+root.right.val : return True else : return False Colored by Color Scripter cs 2022. 7. 7. leetcode 128. Longest Consecutive Sequence 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 class Solution: def longestConsecutive(self, nums: List[int]) -> int: nums=list(set(nums)) nums.sort() ans=1 start=1 for i in range(1,len(nums)): if nums[i]-1 == nums[i-1] : start+=1 else : ans=max(ans,start) start=1 ans=max(ans,start) if len(nums) ==0 : ans=0 return ans Colored by Color Scripter cs 2022. 7. 6. leetcode 509. Fibonacci Number 1 2 3 4 5 class Solution: def fib(self, n: int) -> int: if n==0 : return 0 elif n== 1: return 1 else : return self.fib(n-1)+self.fib(n-2) cs memoization 이나 DP 방식으로도 풀 수있는데 recursion으로 풀어도 time limit 안걸리고 되네용 2022. 7. 6. leetcode 462. Minimum Moves to Equal Array Elements II 1 2 3 4 5 6 7 8 from statistics import median class Solution: def minMoves2(self, nums: List[int]) -> int: med=median(nums) ans=0 for i in nums : ans+=abs(med-i) return int(ans) cs 2022. 6. 30. 이전 1 ··· 13 14 15 16 17 18 19 ··· 29 다음