Algorithm(218)
-
[Leetcode]238. Product of Array Except Self
1. problem : https://leetcode.com/problems/product-of-array-except-self/description/?envType=study-plan-v2&envId=leetcode-75 2. solution 1 :class Solution: def productExceptSelf(self, nums: List[int]) -> List[int]: n = len(nums) result = [1] * n # Calculate left products left = 1 for i in range(n): result[i] = left left *= nums[..
2024.07.27 -
[Leetcode]151. Reverse Words in a String
1. problem : https://leetcode.com/problems/reverse-words-in-a-string/description/?envType=study-plan-v2&envId=leetcode-75 2. solution 1 : class Solution: def reverseWords(self, s: str) -> str: s = s.split(" ") s = [i for i in s if i] s.reverse() return " ".join(s)split으로 s를 단어별로 구분하는 리스트를 만들고, 이 리스트에 빈값을 없애준다. 그다음, reverse 시켜서 , 단어의 위치를 역순으로 만들어준 다음. " ". jo..
2024.07.26 -
[Leetcode]345. Reverse Vowels of a String
1. Problem : https://leetcode.com/problems/reverse-vowels-of-a-string/description/?envType=study-plan-v2&envId=leetcode-75 2. Solution 1 : class Solution: def reverseVowels(self, s: str) -> str: vowel_list = ["a","e","i","o","u","A","E","I","O","U"] string_list = list(s) left,right = 0,len(string_list)-1 while left 위 solution은 str을 리스트로 만든 다음, left, right ..
2024.07.26 -
[Leetcode]605. Can Place Flowers
1. Problem : https://leetcode.com/problems/can-place-flowers/?envType=study-plan-v2&envId=leetcode-75 2. Solution1 : class Solution: def canPlaceFlowers(self, flowerbed: List[int], n: int) -> bool: flowerbed.insert(0,0) flowerbed.append(0) count = 0 i = 1 while i 0: if flowerbed[i-1] == 0 and flowerbed[i+1] == 0 and flowerbed[i] == 0: ..
2024.07.25 -
[Leetcode]1431. Kids With the Greatest Number of Candies
1. 문제 :https://leetcode.com/problems/kids-with-the-greatest-number-of-candies/description/?envType=study-plan-v2&envId=leetcode-75 2. 풀이 : class Solution: def kidsWithCandies(self, candies: List[int], extraCandies: int) -> List[bool]: if not candies: return [] max_candies = max(candies) for i in range(len(candies)): if candies[i] + extraCandies >= m..
2024.07.25 -
[Leetcode]894. All Possible Full Binary Trees
1. 문제 : Given an integer n, return a list of all possible full binary trees with n nodes. Each node of each tree in the answer must have Node.val == 0.Each element of the answer is the root node of one possible tree. You may return the final list of trees in any order.A full binary tree is a binary tree where each node has exactly 0 or 2 children. Example 1:Input: n = 7Output: [[0,0,0,null,null,..
2024.07.25