From 0169df984e7e8cfd1d1b056cd7e0282781b26d6d Mon Sep 17 00:00:00 2001 From: KyungJin Jung Date: Wed, 5 Aug 2026 00:59:45 +0900 Subject: [PATCH 1/2] 206. Reverse Linked List --- reverse-linked-list/okyungjin.py | 50 ++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 reverse-linked-list/okyungjin.py diff --git a/reverse-linked-list/okyungjin.py b/reverse-linked-list/okyungjin.py new file mode 100644 index 0000000000..50bf87b3e6 --- /dev/null +++ b/reverse-linked-list/okyungjin.py @@ -0,0 +1,50 @@ +# https://leetcode.com/problems/reverse-linked-list/ + +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, val=0, next=None): +# self.val = val +# self.next = next + +""" +Time: O(N) +Space O(N) +""" +class Solution: + def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]: + if not head: + return None + + stack = [] + + while head: + stack.append(head) + head = head.next + + dummy_head = ListNode() + curr = dummy_head + + while stack: + curr.next = stack.pop() + curr = curr.next + + curr.next = None + + return dummy_head.next + + +""" +Time: O(N) +Space O(1) +""" +class Solution: + def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]: + prev = None + curr = head + + while curr: + temp = curr.next + curr.next = prev + prev, curr = curr, temp + + return prev From 1b4efaaa4dccf0790182fe1af615dff3f49aa227 Mon Sep 17 00:00:00 2001 From: KyungJin Jung Date: Sat, 8 Aug 2026 17:50:26 +0900 Subject: [PATCH 2/2] 3. Longest Substring Without Repeating Characters --- .../okyungjin.py | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 longest-substring-without-repeating-characters/okyungjin.py diff --git a/longest-substring-without-repeating-characters/okyungjin.py b/longest-substring-without-repeating-characters/okyungjin.py new file mode 100644 index 0000000000..9ec4769df0 --- /dev/null +++ b/longest-substring-without-repeating-characters/okyungjin.py @@ -0,0 +1,24 @@ +""" +N: `s`의 길이, M: `s`에서 중복을 제외한 문자의 개수 +Time: O(N) +Space: O(min(N,M)) +""" +class Solution: + def lengthOfLongestSubstring(self, s: str) -> int: + # 문자의 최근 인덱스를 저장 + char_map = {} + + left = 0 + max_len = 0 + + for right, char in enumerate(s): + if char in char_map and char_map[char] >= left: + left = char_map[char] + 1 + + char_map[char] = right + + curr_len = right - left + 1 + if curr_len > max_len: + max_len = curr_len + + return max_len