From 87711b96c50db46385c3f6f4fce5ef372ed0c965 Mon Sep 17 00:00:00 2001 From: Gregory Hogg Date: Sun, 16 Feb 2025 21:49:01 -0500 Subject: [PATCH 1/5] Update Linked List Cycle - Leetcode 141.py --- .../Linked List Cycle - Leetcode 141.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Linked List Cycle - Leetcode 141/Linked List Cycle - Leetcode 141.py b/Linked List Cycle - Leetcode 141/Linked List Cycle - Leetcode 141.py index da86af6..d0b3fd7 100644 --- a/Linked List Cycle - Leetcode 141/Linked List Cycle - Leetcode 141.py +++ b/Linked List Cycle - Leetcode 141/Linked List Cycle - Leetcode 141.py @@ -1,8 +1,6 @@ class Solution: def hasCycle(self, head: Optional[ListNode]) -> bool: - dummy = ListNode() - dummy.next = head - slow = fast = dummy + slow = fast = head while fast and fast.next: fast = fast.next.next From 9f071de0ca4519dfe90a9df54928b8078c0c46c4 Mon Sep 17 00:00:00 2001 From: Gregory Hogg Date: Thu, 20 Feb 2025 15:59:19 -0500 Subject: [PATCH 2/5] Update Rotting Oranges - Leetcode 994.py --- .../Rotting Oranges - Leetcode 994.py | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/Rotting Oranges - Leetcode 994/Rotting Oranges - Leetcode 994.py b/Rotting Oranges - Leetcode 994/Rotting Oranges - Leetcode 994.py index 32f3ce0..54ec593 100644 --- a/Rotting Oranges - Leetcode 994/Rotting Oranges - Leetcode 994.py +++ b/Rotting Oranges - Leetcode 994/Rotting Oranges - Leetcode 994.py @@ -1,3 +1,43 @@ +# Code for Bootcamp +class Solution: + from collections import deque + + def orangesRotting(self, grid): + # Initialize variables + Minute = 0 + Q = deque() + FreshCount = 0 + M, N = len(grid), len(grid[0]) + + # Populate queue with initial rotten oranges and count fresh oranges + for i in range(M): + for j in range(N): + if grid[i][j] == 2: + Q.append((i, j)) + elif grid[i][j] == 1: + FreshCount += 1 + + # Directions for adjacent cells (right, down, left, up) + Directions = [(0, 1), (1, 0), (0, -1), (-1, 0)] + + # Perform BFS + while Q and FreshCount > 0: + NumRotting = len(Q) + for _ in range(NumRotting): + i, j = Q.popleft() + for r, c in [(i, j + 1), (i + 1, j), (i, j - 1), (i - 1, j)]: + if 0 <= r < M and 0 <= c < N and grid[r][c] == 1: + grid[r][c] = 2 + FreshCount -= 1 + Q.append((r, c)) + Minute += 1 # Increment minute after processing all rotten oranges in this round + + # Return the time taken or -1 if fresh oranges remain + return Minute if FreshCount == 0 else -1 + + + +# Code for YouTube Video from collections import deque class Solution: def orangesRotting(self, grid: List[List[int]]) -> int: From 0a2d746baf1a4d69fdefd308454ff61378df26d0 Mon Sep 17 00:00:00 2001 From: Gregory Hogg Date: Thu, 20 Feb 2025 20:24:08 -0500 Subject: [PATCH 3/5] Update Course Schedule II - Leetcode 210.py --- .../Course Schedule II - Leetcode 210.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Course Schedule II - Leetcode 210/Course Schedule II - Leetcode 210.py b/Course Schedule II - Leetcode 210/Course Schedule II - Leetcode 210.py index ed8bfab..cd8d244 100644 --- a/Course Schedule II - Leetcode 210/Course Schedule II - Leetcode 210.py +++ b/Course Schedule II - Leetcode 210/Course Schedule II - Leetcode 210.py @@ -7,7 +7,6 @@ def findOrder(self, numCourses: int, prerequisites: List[List[int]]) -> List[int UNVISITED, VISITING, VISITED = 0, 1, 2 states = [UNVISITED] * numCourses - def dfs(i): if states[i] == VISITING: From fcc230cffaf190305568fda1a5ed40976c137ffa Mon Sep 17 00:00:00 2001 From: Gregory Hogg Date: Thu, 20 Feb 2025 20:58:36 -0500 Subject: [PATCH 4/5] Update Rotting Oranges - Leetcode 994.py --- .../Rotting Oranges - Leetcode 994.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/Rotting Oranges - Leetcode 994/Rotting Oranges - Leetcode 994.py b/Rotting Oranges - Leetcode 994/Rotting Oranges - Leetcode 994.py index 54ec593..c14eb3f 100644 --- a/Rotting Oranges - Leetcode 994/Rotting Oranges - Leetcode 994.py +++ b/Rotting Oranges - Leetcode 994/Rotting Oranges - Leetcode 994.py @@ -17,9 +17,6 @@ def orangesRotting(self, grid): elif grid[i][j] == 1: FreshCount += 1 - # Directions for adjacent cells (right, down, left, up) - Directions = [(0, 1), (1, 0), (0, -1), (-1, 0)] - # Perform BFS while Q and FreshCount > 0: NumRotting = len(Q) From 53e6c8afdf4fdc3fa0b69b18818f93cc0adac3b3 Mon Sep 17 00:00:00 2001 From: Gregory Hogg Date: Thu, 2 Oct 2025 16:50:49 -0400 Subject: [PATCH 5/5] Update Daily Temperatures - Leetcode 739.py --- .../Daily Temperatures - Leetcode 739.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Daily Temperatures - Leetcode 739/Daily Temperatures - Leetcode 739.py b/Daily Temperatures - Leetcode 739/Daily Temperatures - Leetcode 739.py index b39b3cb..8fd91a4 100644 --- a/Daily Temperatures - Leetcode 739/Daily Temperatures - Leetcode 739.py +++ b/Daily Temperatures - Leetcode 739/Daily Temperatures - Leetcode 739.py @@ -1,3 +1,19 @@ +# Brute Force +class Solution: + def dailyTemperatures(self, temperatures: List[int]) -> List[int]: + n = len(temperatures) + answer = [0] * n + for i in range(n): + for j in range(i+1, n): + if temperatures[j] > temperatures[i]: + answer[i] = j - i + break + + return answer +# Time: O(n^2) +# Space: O(1) + +# Optimal class Solution: def dailyTemperatures(self, temperatures: List[int]) -> List[int]: temps = temperatures