[leetcode-232] Implement Queue using Stacks
ยท
๐Ÿข One step
LeetCode-232 Implement Queue using Stacks : Implement a first in first out (FIFO) queue using only two stacks. The implemented queue should support all the functions of a normal queue (push, peek, pop, and empty). note : sub์„ ์ž…์„ ์ถœ :::python class MyQueue: def init(self): self.temp = collections.deque() def push(self, x: int) -> None: self.temp.append(x) def pop(self) -> int: return self.temp.pople..
[leetcode-225] Implement Queue using Stacks
ยท
๐Ÿข One step
LeetCode-225 Implement Queue using Stacks : Implement a last-in-first-out (LIFO) stack using only two queues. The implemented stack should support all the functions of a normal stack note : last-in-first-out (LIFO) Answer :::python class MyStack: def init(self): self.temp = [] def push(self, x: int) -> None: self.temp.append(x) def pop(self) -> int: return self.temp.pop() def top(self) -> int: r..
[leetcode 739] Daily Temperature
ยท
๐Ÿข One step
LeetCode-739 Daily Temperature : ๋ช‡ ์ผ ํ›„ ๊ธฐ์˜จ์ด ์˜ค๋ฅผ๊นŒ? note : Answer :::python class Solution: def dailyTemperatures(self, temperatures: List[int]) -> List[int]: out = [] left, right = 0, 0 while left != len(temperatures)-1: day = 0 check = 0 while right temperatures[stack[-1]]: last = stack.pop() answer[last] = i - last stack.append(i) return answer Result : 1352ms Memory: 28.6mb
[LeetCode-316] Remove Duplicate Letters
ยท
๐Ÿข One step
LeetCode-316 Remove Duplicate Letters : Given a string s, remove duplicate letters so that every letter appears once and only once. You must make sure your result is the smallest in lexicographical order among all possible results. note :Answer :::python class Solution: def removeDuplicateLetters(self, s: str) -> str: for char in sorted(set(s)): suffix = s[s.index(char):] if set(s)==set(suffix):..
[leetcode-20] Valid Parenthese
ยท
๐Ÿข One step
LeetCode-20 Valid Parentheses : Given a string s containing just the characters (, ), {, }, [ and ], determine if the input string is valid. note : s consists of parentheses only ()[]{}Answer :::python class Solution: def isValid(self, s: str) -> bool: valid = [] dict_valid = { "}":"{", "]":"[", ")":"(" } for l in s: if l not in dict_valid: valid.append(l) elif not valid or dict_valid[l] != vali..
[leetcode 92] Reverse Linked List II
ยท
๐Ÿข One step
LeetCode-92 Reverse Linked List II : Given the head of a singly linked list and two integers left and right where left
[leetcode-24] Swap-Nodes-In-Pairs_2
ยท
๐Ÿข One step
LeetCode-24 swap-nodes-in-pairs_2 : Given a linked list, swap every two adjacent nodes and return its head. You must solve the problem without modifying the values in the list's nodes note : only nodes themselves may be changed.MyAnswer :::python # Definition for singly-linked list. # class ListNode: # def init(self, val=0, next=None): # self.val = val # self.next = next class Solution: def swap..
[leetcode 24] Swap Nodes in Pairs
ยท
๐Ÿข One step
LeetCode-24 swap-nodes-in-pairs : Given a linked list, swap every two adjacent nodes and return its head. You must solve the problem without modifying the values in the list's nodes note : only nodes themselves may be changed.MyAnswer :::python # Definition for singly-linked list. # class ListNode: # def init(self, val=0, next=None): # self.val = val # self.next = next class Solution: def swapPa..
๋‹คํ–ˆ๋‹ค