Skip to content

Commit 1bc30ff

Browse files
committed
cleanup
1 parent c77c617 commit 1bc30ff

8 files changed

+18
-7
lines changed

Diff for: 1235.JobScheduling.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ public int JobScheduling(int[] startTime, int[] endTime, int[] profit)
3030
int n = profit.Length;
3131
maxProfit = new int[n];
3232

33+
// Initialize max profit array with -1 for memoization
34+
Array.Fill(maxProfit, -1);
35+
3336
// Create job tuples containing start, end times, and profit
3437
(int start, int end, int profit)[] jobs = new (int, int, int)[n];
3538
for (int i = 0; i < n; i++)
@@ -40,9 +43,6 @@ public int JobScheduling(int[] startTime, int[] endTime, int[] profit)
4043
// Sort jobs by their start time to facilitate recursive exploration
4144
jobs = jobs.OrderBy(x => x.start).ToArray();
4245

43-
// Initialize max profit array with -1 for memoization
44-
Array.Fill(maxProfit, -1);
45-
4646
return Scheduling(jobs, 0, 0);
4747
}
4848

Diff for: 236.LowestCommonAncestor.cs

+2
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,11 @@ public TreeNode LowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
4747
TreeNode left = LowestCommonAncestor(root.left, p, q);
4848
TreeNode right = LowestCommonAncestor(root.right, p, q);
4949

50+
//one node is in left and one in right
5051
if(left != null && right != null)
5152
return root;
5253

54+
//both the node are in one side of tree.
5355
return right ?? left;
5456
}
5557
}

Diff for: 239.MaxSlidingWindow.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public int[] MaxSlidingWindow(int[] nums, int k) {
1313
if (nums == null || nums.Length == 0) return new int[0];
1414

1515
int n = nums.Length;
16-
int[] res = new int[n - k + 1];
16+
int[] res = new int[n - k + 1]; // steores result i.e. max of k wincow
1717
LinkedList<int> deque = new LinkedList<int>(); // Stores indices of elements
1818

1919
for (int i = 0; i < nums.Length; i++) {

Diff for: 42.Trap.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
// Example :
77
// Input: height = [0,1,0,2,1,0,1,3,2,1,2,1]
88
// Output: 6
9-
// Explanation: The above elevation map (black section) is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped.
9+
// Explanation: The above elevation map (black section) is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water
10+
// (blue section) are being trapped.
1011

1112

1213
//Prefix Sum

Diff for: 524.FindLongestWord.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// 524. Longest Word in Dictionary through Deleting
2-
// Given a string s and a string array dictionary, return the longest string in the dictionary that can be formed by deleting some of the given string characters. If there is more than one possible result, return the longest word with the smallest lexicographical order. If there is no possible result, return the empty string.
2+
// Given a string s and a string array dictionary, return the longest string in the dictionary that can be formed by deleting
3+
// some of the given string characters. If there is more than one possible result, return the longest word with the smallest l
4+
// exicographical order. If there is no possible result, return the empty string.
35

46
// Example 1:
57
// Input: s = "abpcplea", dictionary = ["ale","apple","monkey","plea"]

Diff for: 64.MinPathSum.cs

+5
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,20 @@ public int MinPathSum(int[][] grid)
2929
}
3030
public int PathSum(int[][] grid, int i, int j)
3131
{
32+
// already visited
3233
if (visited[i, j] > -1)
3334
return visited[i, j];
3435
int result;
36+
// reached destination
3537
if (i == grid.Length - 1 && j == grid[0].Length - 1)
3638
result = grid[i][j];
39+
//Last Row
3740
else if (i == grid.Length - 1)
3841
result = grid[i][j] + PathSum(grid, i, j + 1);
42+
//Last Column
3943
else if (j == grid[0].Length - 1)
4044
result = grid[i][j] + PathSum(grid, i + 1, j);
45+
//All others
4146
else
4247
result = grid[i][j] + Math.Min(PathSum(grid, i+1, j), PathSum(grid, i, j + 1));
4348
visited[i,j] = result;

Diff for: Graph.DetectCycle.cs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
// DFS
32
public class Solution {
43
public void DetectCycle(int[][] edges, int n) {

Diff for: LargestTree.cs

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
// Result Selection:
3232

3333
// After merging, the tree with the largest size is selected. In case of ties, the smallest root ID is chosen.
34+
35+
3436
// Complexity Analysis:
3537
// Time Complexity: O(NlogN) due to efficient path compression and union operations.
3638
// Space Complexity: O(N) for the parent and size dictionaries.

0 commit comments

Comments
 (0)