코-딩/Leetcode

코-딩/Leetcode

[leetcode] 62. Unique Paths

문제 : https://leetcode.com/problems/unique-paths/description/ 난이도 : Medium 풀이 1) dp로 풀기 class Solution: def uniquePaths(self, m: int, n: int) -> int: if not m or not n: return 0 cur = [1] * n for i in range(1, m): for j in range(1, n): cur[j] += cur[j - 1] return cur[-1] 2) 수학적으로 풀기 class Solution: def uniquePaths(self, m: int, n: int) -> int: return factorial(m+n-2) // factorial(m-1) // factoria..

코-딩/Leetcode

[leetcode] 1331. Rank Transform of an Array

문제 : https://leetcode.com/problems/rank-transform-of-an-array/description/ Rank Transform of an Array - LeetCode Can you solve this real interview question? Rank Transform of an Array - Given an array of integers arr, replace each element with its rank. The rank represents how large the element is. The rank has the following rules: * Rank is an integer starting from leetcode.com 난이도 : Easy 풀이 cl..

코-딩/Leetcode

[leetcode] 1417. Reformat The String

문제 : https://leetcode.com/problems/reformat-the-string/description/ Reformat The String - LeetCode Can you solve this real interview question? Reformat The String - You are given an alphanumeric string s. (Alphanumeric string is a string consisting of lowercase English letters and digits). You have to find a permutation of the string where no letter is leetcode.com 난이도 : Easy 풀이 class Solution: ..

코-딩/Leetcode

[leetCode] 1592. Rearrange Spaces Between Words

문제 : https://leetcode.com/problems/rearrange-spaces-between-words/description/ Rearrange Spaces Between Words - LeetCode Can you solve this real interview question? Rearrange Spaces Between Words - You are given a string text of words that are placed among some number of spaces. Each word consists of one or more lowercase English letters and are separated by at least one spa leetcode.com 난이도 : E..

코-딩/Leetcode

[leetcode] 17. Letter Combinations of a Phone Number

문제 : https://leetcode.com/problems/letter-combinations-of-a-phone-number/ 난이도 : Medium 풀이 class Solution: def letterCombinations(self, digits: str) -> List[str]: dict = {'2':"abc", '3':"def", '4':"ghi", '5':"jkl", '6':"mno", '7': "pqrs", '8':"tuv", '9':"wxyz"} comb = [''] if digits else [] for d in digits: comb = [p + q for p in comb for q in dict[d]] return comb

코-딩/Leetcode

[Leetcode] 11. Container With Most Water

문제 : https://leetcode.com/problems/container-with-most-water/ 난이도 : Medium 풀이 class Solution: def maxArea(self, height: List[int]) -> int: l, r = 0, len(height) - 1 water = 0 while l < r: water = max(water, (r - l) * min(height[l], height[r])) # 저장할 수 있는 최대 물 if height[l] < height[r]: l += 1 else: r -= 1 return water 대학생 때 풀었던 거 같은데.. 오랜만에 보는 문제ㅎㅎ 왼쪽에서 움직이는 포인터(l)와 오른쪽에서 움직이는 포인터(r)를 두고 저장할 수 있는..

힞뚜루마뚜루
'코-딩/Leetcode' 카테고리의 글 목록