From 1f2cb01ff74771c37cb00d6bfcd9e0fa65ec2175 Mon Sep 17 00:00:00 2001 From: printjin Date: Sun, 11 May 2025 10:12:24 +0900 Subject: [PATCH 1/7] Fear : Reverse Linked List --- reverse-linked-list/printjin-gmailcom.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 reverse-linked-list/printjin-gmailcom.py diff --git a/reverse-linked-list/printjin-gmailcom.py b/reverse-linked-list/printjin-gmailcom.py new file mode 100644 index 000000000..ce398fb56 --- /dev/null +++ b/reverse-linked-list/printjin-gmailcom.py @@ -0,0 +1,16 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, val=0, next=None): +# self.val = val +# self.next = next + +class Solution: + def reverseList(self, head): + prev = None + current = head + while current: + nxt = current.next + current.next = prev + prev = current + current = nxt + return prev \ No newline at end of file From ce62423c03a12f017a405f966afa15ee5fdbcd2f Mon Sep 17 00:00:00 2001 From: printjin Date: Sun, 11 May 2025 10:17:11 +0900 Subject: [PATCH 2/7] Fix : LineLint Error --- reverse-linked-list/printjin-gmailcom.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/reverse-linked-list/printjin-gmailcom.py b/reverse-linked-list/printjin-gmailcom.py index ce398fb56..5b9338d0e 100644 --- a/reverse-linked-list/printjin-gmailcom.py +++ b/reverse-linked-list/printjin-gmailcom.py @@ -13,4 +13,5 @@ def reverseList(self, head): current.next = prev prev = current current = nxt - return prev \ No newline at end of file + return prev + \ No newline at end of file From dc2adccc878a18698091214cf48e08db6a061062 Mon Sep 17 00:00:00 2001 From: printjin Date: Sun, 11 May 2025 10:18:25 +0900 Subject: [PATCH 3/7] Fix : LineLint Error --- reverse-linked-list/printjin-gmailcom.py | 1 - 1 file changed, 1 deletion(-) diff --git a/reverse-linked-list/printjin-gmailcom.py b/reverse-linked-list/printjin-gmailcom.py index 5b9338d0e..749921884 100644 --- a/reverse-linked-list/printjin-gmailcom.py +++ b/reverse-linked-list/printjin-gmailcom.py @@ -14,4 +14,3 @@ def reverseList(self, head): prev = current current = nxt return prev - \ No newline at end of file From e97b0e90bca7a410b61340f44f82bf13fe1c99fd Mon Sep 17 00:00:00 2001 From: printjin Date: Sun, 11 May 2025 10:42:47 +0900 Subject: [PATCH 4/7] Feat : Longest Substring Without Repeating Characters --- .../printjin-gmailcom.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 longest-substring-without-repeating-characters/printjin-gmailcom.py diff --git a/longest-substring-without-repeating-characters/printjin-gmailcom.py b/longest-substring-without-repeating-characters/printjin-gmailcom.py new file mode 100644 index 000000000..e8cea37f7 --- /dev/null +++ b/longest-substring-without-repeating-characters/printjin-gmailcom.py @@ -0,0 +1,14 @@ +class Solution: + def lengthOfLongestSubstring(self, s): + char_set = set() + left = 0 + max_len = 0 + + for right in range(len(s)): + while s[right] in char_set: + char_set.remove(s[left]) + left += 1 + char_set.add(s[right]) + max_len = max(max_len, right - left + 1) + + return max_len From c3d4fd8e189e691fb5262495fe3ca30f9ce6b811 Mon Sep 17 00:00:00 2001 From: printjin Date: Sun, 11 May 2025 10:48:27 +0900 Subject: [PATCH 5/7] Feat : Number of Islands --- number-of-islands/printjin-gmailcom.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 number-of-islands/printjin-gmailcom.py diff --git a/number-of-islands/printjin-gmailcom.py b/number-of-islands/printjin-gmailcom.py new file mode 100644 index 000000000..ed64bc8a4 --- /dev/null +++ b/number-of-islands/printjin-gmailcom.py @@ -0,0 +1,24 @@ +class Solution: + def numIslands(self, grid): + if not grid: + return 0 + + rows, cols = len(grid), len(grid[0]) + count = 0 + + def dfs(r, c): + if r < 0 or c < 0 or r >= rows or c >= cols or grid[r][c] == "0": + return + grid[r][c] = "0" + dfs(r+1, c) + dfs(r-1, c) + dfs(r, c+1) + dfs(r, c-1) + + for r in range(rows): + for c in range(cols): + if grid[r][c] == "1": + dfs(r, c) + count += 1 + + return count From 28fb96ad9cfeacba995aaf23edaa2d3a20177ecd Mon Sep 17 00:00:00 2001 From: printjin Date: Sun, 11 May 2025 10:51:47 +0900 Subject: [PATCH 6/7] Feat : Unique Paths --- unique-paths/printjin-gmailcom.py | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 unique-paths/printjin-gmailcom.py diff --git a/unique-paths/printjin-gmailcom.py b/unique-paths/printjin-gmailcom.py new file mode 100644 index 000000000..46123174e --- /dev/null +++ b/unique-paths/printjin-gmailcom.py @@ -0,0 +1,7 @@ +class Solution: + def uniquePaths(self, m, n): + dp = [[1] * n for _ in range(m)] + for i in range(1, m): + for j in range(1, n): + dp[i][j] = dp[i - 1][j] + dp[i][j - 1] + return dp[m - 1][n - 1] From d0d3502b3d202c2a102b7af997e5f069ce89c665 Mon Sep 17 00:00:00 2001 From: printjin Date: Sun, 11 May 2025 10:53:00 +0900 Subject: [PATCH 7/7] Feat : Set Matrix Zeroes --- set-matrix-zeroes/printjin-gmailcom.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 set-matrix-zeroes/printjin-gmailcom.py diff --git a/set-matrix-zeroes/printjin-gmailcom.py b/set-matrix-zeroes/printjin-gmailcom.py new file mode 100644 index 000000000..41273d4f6 --- /dev/null +++ b/set-matrix-zeroes/printjin-gmailcom.py @@ -0,0 +1,23 @@ +class Solution: + def setZeroes(self, matrix): + first_row_zero = any(matrix[0][j] == 0 for j in range(len(matrix[0]))) + first_col_zero = any(matrix[i][0] == 0 for i in range(len(matrix))) + + for i in range(1, len(matrix)): + for j in range(1, len(matrix[0])): + if matrix[i][j] == 0: + matrix[i][0] = 0 + matrix[0][j] = 0 + + for i in range(1, len(matrix)): + for j in range(1, len(matrix[0])): + if matrix[i][0] == 0 or matrix[0][j] == 0: + matrix[i][j] = 0 + + if first_row_zero: + for j in range(len(matrix[0])): + matrix[0][j] = 0 + + if first_col_zero: + for i in range(len(matrix)): + matrix[i][0] = 0