[leetcode-42] Trapping Rain Water
ยท
๐Ÿข One step
LeetCode-42 Trapping Rain Water : Trapping rain water. find volume note : Tip: swapAnswer :::python class Solution: def trap(self, height: List[int]) -> int: if not height: return 0 volume = 0 left, right = 0, len(height) - 1 left_max, right_max = height[left], height[right] while left
[leetcode-1] Two Sum
ยท
๐Ÿข One step
LeetCode-1 Two Sum : target๊ณผ ์ผ์น˜ํ•˜๋Š” ๋ฆฌ์ŠคํŠธ ๋‘๊ฐœ์˜ ํ•ฉ note : OMyAnswer (O(n * n))class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: len_nums = len(nums) if len_nums==2: return [0,1] for i in range(len(nums)): for j in range(i+1,len(nums)): if target==(nums[i]+nums[j]): return [i, j] Result : 3649ms Memory: 14.9mbAnswer O(n * n) (in์˜ ์‹œ๊ฐ„ ๋ณต์žก๋„ n)class Solution: def twoSum(self, nums:..
[leetcode-5] Longest Palindrome Substring
ยท
๐Ÿข One step
LeetCode-5 Longest Palindrome Substring : ๊ฐ€์žฅ ๊ธด Palindrome note :Myanswerclass Solution: def longestPalindrome(self, s: str) -> str: if len(s)==1: return s[0] for i in range(0,len(s)-1): for j in range(0,i+1): org = s[j:len(s)-(-j+i)] if org[::-1]==org: return org return org[0] Result : 6515ms Memory: 13.9mbSolutionclass Solution: def longestPalindrome(self, s: str) -> str: def expend(left: int, ..
[leetcode-49] Group Anagrams
ยท
๐Ÿข One step
LeetCode-49 Group Anagrams : ์–ธ์–ด์œ ํฌ ex) cat -> act cat note : hint: collections.defaultdict(list)class Solution: def groupAnagrams(self, strs: List[str]) -> List[List[str]]: anagrams = defaultdict(list) for word in strs: anagrams[''.join(sorted(word))].append(word) return list(anagrams.values()) Result : 98ms Memory: 17.2mbdefault_factory: index[x] ์—์„œ x๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์„ ๋•Œ ValueError๋•Œ ๋ฐœ์ƒํ•œ๋‹ค. ๋ชจ๋“  ๊ตฌํ˜„์ด ..
LeetCode - Time complexity ์‹œ๊ฐ„ ๋ณต์žก๋„
ยท
๐Ÿข One step
https://www.reddit.com/r/leetcode/comments/w26u7o/could_someone_please_explain_the_difference_in/ https://www.reddit.com/r/MLQuestions/comments/wz7s5h/can_someone_explain_time_complexity_and_what_doe/ r/MLQuestions on Reddit: Can someone explain time complexity and what doe sit has to do with data structures like LinkedList and Posted by u/Important-Asparagus9 - 1 vote and 4 comments www.reddit...
[leetcode-819] Most Common Word
ยท
๐Ÿข One step
LeetCode-819 Most Common Word : ๊ธˆ์ง€๋œ ๋‹จ์–ด๋ฅผ ์ œ์™ธํ•œ ๊ฐ€์žฅ ๋งŽ์€ ๋นˆ๋„์˜ ๋‹จ์–ด ์ถ”์ถœ Info : ๋Œ€์†Œ ๋ฌธ์ž, ๊ตฌ๋‘์  ๋ฌด์‹œclass Solution: def mostCommonWord(self, paragraph: str, banned: List[str]) -> str: return Counter([word for word in re.sub("[^a-z]", ' ',paragraph.lower()).split() if word not in banned]).most_common(1)[0][0] Result : 28 Memory: 13.9mb
[leetcode-937] Reorder_Data_in_LogFile
ยท
๐Ÿข One step
LeetCode-937 Reorder_Data_in_LogFile : reorder log files ์ฒซ๋ฒˆ์งธ ๋ฌธ์ž ์‹๋ณ„์ž ex) "dig2 a","dig1 b"-> "a","b"Myanswerclass Solution: def reorderLogFiles(self, logs: List[str]) -> List[str]: let = [] digit = [] for i in logs: if i.split()[1].isdigit()==False: let.append(i) else: digit.append(i) let.sort(key = lambda x: (x.split()[1:], x.split()[0])) #digit.sort(key = lambda x: x.split()[1:],reverse=True) r..
[leetcode-344] ReverseString
ยท
๐Ÿข One step
LeetCode-344 ReverseString : ๋ฌธ์ž์—ด ๋ฆฌ์ŠคํŠธ ๋’ค์ง‘๊ธฐ ๋ฆฌํ„ด ์—†์ด ๋ฆฌ์ŠคํŠธ ๋‚ด๋ถ€์˜ ์ฃผ์†Œ ๊ฐ’์ด ๋ณ€ํ•˜๋„๋ก my answer class Solution: def reverseString(self, s: List[str]) -> None: """ Do not return anything, modify s in-place instead. """ for i in range(len(s)): s.append(s.pop(-i-1)) Result : 394 Memory: 18.4mb 1. ํˆฌ ํฌ์ธํŠธ ์Šค์™‘ {code} Result : 205 Memory: 18.5mb
๋‹คํ–ˆ๋‹ค
'๐Ÿข One step' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๊ธ€ ๋ชฉ๋ก (6 Page)