💻 Study/🧩 알고리즘

    리트코드] 316. Remove Duplicate Letters.

    [문제] Remove Duplicate Letters - 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 [코드] class Solution: def removeDuplicateLetters(self, s: str) -> str: answer = [] index = 0 for c in s: index += 1 if c in answer: continue while answer: top = answer[-1] if c < top and top in s[index:]..

    리트코드] 20. Valid Parentheses

    [문제] Valid Parentheses - 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 [코드] class Solution: def isValid(self, s: str) -> bool: stack = [] parenthes = {")":"(", "}":"{", "]":"["} for c in s: if parenthes.get(c): if stack: pop = stack.pop() if pop != parenthes.get(c): return False ..

    리트코드] 92. Reverse Linked List II

    [문제] Reverse Linked List II - 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 [코드] class Solution: def reverseBetween(self, head: Optional[ListNode], left: int, right: int) -> Optional[ListNode]: if head is None or left == right: return head sol = solHead = ListNode(0) node = solHe..

    리트코드] 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 [코드] def oddEvenList(self, head: Optional[ListNode]) -> Optional[ListNode]: if head is None: return head odd = head evenRoot = even = head.next while even and even.next: odd.next = even.next odd = odd.next ..

    리트코드] 24. Swap Nodes in Pairs

    [문제] Swap Nodes in Pairs - 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 [코드 class Solution: def swapPairs(self, head: Optional[ListNode]) -> Optional[ListNode]: answer = swapNode = ListNode(0) swapNode.next = head while head and head.next: next = head.next head.next = next.next ..

    리트코드] 2. Add Two Numbers

    [문제] Add Two Numbers - 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 [코드] def isPalindrome(self, l1: ListNode, l2: ListNode) -> ListNode: nodeSum = ListNode(0) head = nodeSum carry = 0 while l1 or l2 or carry: sum = 0 if l1 is not None: sum += l1.val l1 = l1.next if l2 is not Non..

    리트코드] 206. Reverse Linked List

    [문제] Reverse 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 [코드] class Solution: def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]: node = head sol = None while node is not None: next = node.next node.next = sol sol = node node = next return sol [..

    리트코드] 234. Palindrome Linked List

    [문제] https://leetcode.com/problems/palindrome-linked-list/ Palindrome 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 [코드] def isPalindrome(self, head: Optional[ListNode]) -> bool: q: Deque = collections.deque() node = head if not head: return True while node is not N..

    리트코드] 121. Best Time to Buy and Sell Stock

    [문제] https://leetcode.com/problems/best-time-to-buy-and-sell-stock/ Best Time to Buy and Sell Stock - 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 [코드] def maxProfit(self, prices: List[int]) -> int: answer = 0 min_day = 0 for index in range(len(prices)): max_profit = prices[inde..

    리트코드] 238. Product of Array Except Self

    [문제] https://leetcode.com/problems/product-of-array-except-self/ Product of Array Except Self - 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 [코드] class Solution: def productExceptSelf(self, nums: List[int]) -> List[int]: sol = [] product = 1 for i in range(len(nums)): sol.append..