본문 바로가기

분류 전체보기

(174)
[Leetcode] 2356. Number of Unique Subjects Taught by Each Teacher https://leetcode.com/problems/number-of-unique-subjects-taught-by-each-teacher/ SELECT teacher_id, COUNT(DISTINCT(subject_id)) as cnt FROM Teacher GROUP BY teacher_id;
[Leetcode] 941. Valid Mountain Array https://leetcode.com/problems/valid-mountain-array/ class Solution: def validMountainArray(self, arr: List[int]) -> bool: increasing = True change = False if len(arr) >= 2 and arr[0] - arr[1] > 0: increasing = False before = arr[0] for i in arr[1:]: if increasing: if i > before: before = i elif i < before: before = i increasing = False change = True else: return False else: if i < before: before..
[Leetcode] 1299. Replace Elements with Greatest Element on Right Side https://leetcode.com/problems/replace-elements-with-greatest-element-on-right-side/ class Solution: def replaceElements(self, arr: List[int]) -> List[int]: result = [] before = max(arr) for i in range(len(arr) - 1): if arr[i] == before: before = max(arr[i+1:]) result.append(before) result.append(-1) return result
[Leetcode] 922. Sort Array By Parity II https://leetcode.com/problems/sort-array-by-parity-ii/ class Solution: def sortArrayByParityII(self, nums: List[int]) -> List[int]: result = [] even_index = 0 odd_index = 1 for i in nums: if i % 2 == 0: result.insert(even_index, i) even_index += 2 else: result.insert(odd_index, i) odd_index += 2 return result
[Leetcode] 905. Sort Array By Parity https://leetcode.com/problems/sort-array-by-parity/ class Solution: def sortArrayByParity(self, nums: List[int]) -> List[int]: result = [] for i in nums: if i % 2 == 0: result.insert(0, i) else: result.append(i) return result
[Leetcode] 620. Not Boring Movies https://leetcode.com/problems/not-boring-movies/ SELECT * FROM Cinema WHERE (MOD(id, 2) = 1) AND (description != "boring") ORDER BY rating desc;
[Leetcode] 26. Remove Duplicates from Sorted Array https://leetcode.com/problems/remove-duplicates-from-sorted-array/ class Solution: def removeDuplicates(self, nums: List[int]) -> int: count = len(nums) before = nums[0] for i in range(1, len(nums)): if before == nums[i]: nums[i] = 101 count -= 1 else: before = nums[i] nums.sort() return count
[Leetcode] 1068. Product Sales Analysis I https://leetcode.com/problems/product-sales-analysis-i/ SELECT p.product_name, s.year, s.price FROM Sales as s INNER JOIN Product as p ON s.product_id = p.product_id;

728x90