Problem Solving/LeetCode(27)
-
[Leetcode] 622. Design Circular Queue
Leetcode 622. Design Circular Queue (3) Design Circular Queue - LeetCode Design Circular Queue - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com Solution class MyCircularQueue: def __init__(self, k: int): self.q = [None] * (k+1) self.max = k + 1 self.front = 0 self.rear = 0 def enQ..
2021.01.18 -
[Leetcode] 232. Implement Queue using Stacks
Leetcode 232 (3) Implement Queue using Stacks - LeetCode Implement Queue using Stacks - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com Solution class MyQueue: def __init__(self): self.stack = [] def push(self, x: int) -> None: self.stack.append(x) def pop(self) -> int: front = sel..
2021.01.18 -
[Leetcode] 225. Implement Stack using Queues
Leetcode 225. Implement Stack using Queues (3) Implement Stack using Queues - LeetCode Implement Stack using Queues - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com Solution from collections import deque class MyStack: def __init__(self): self.q = collections.deque() def push(self..
2021.01.18 -
[Leetcode] 739. Daily Temperatures
Leetcode 739. Daily Temperatures Daily Temperatures - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com Solution class Solution: def dailyTemperatures(self, T: List[int]) -> List[int]: stack = [] result = [0]*len(T) for i, n in enumerate(T): while stack and n > T[stack[-1]]: top = st..
2021.01.18 -
[LeetCode] 20. Valid Parentheses
LeetCode 20. Valid Parentheses Solution class Solution: def isValid(self, s: str) -> bool: stack = [] bracket = { ')': '(', ']': '[', '}': '{' } for char in s: if char not in bracket: stack.append(char) # open bracket elif not stack or bracket[char] != stack.pop(): return False return len(stack) == 0 괄호 짝 딕셔너리로 설정 open bracket일경우 stack에 push open이 없거나, 짝이 안맞을 경우 return False stack에 남아있을 경우(open이..
2021.01.18 -
[LeetCode] 328. Odd Even Linked List
LeetCode 328. Odd Even Linked List Odd Even Linked List - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com Solution # Definition for singly-linked list. class ListNode: def __init__(self, val=0, next=None): self.val = val self.next = next class Solution: def oddEvenList(self, head: ..
2021.01.15