Skip to content

Commit f62cae7

Browse files
committed
Added hints Dec 28
1 parent fd584b8 commit f62cae7

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ Solutions <a href = "https://github.com/aliasvishnu/leetcode/tree/master/Solutio
9595
| 187 | Hash | Store all 10 letter substrings in a hashtable. | O(n) |
9696
| 190 | BF | Remember to store answer in unsigned long. Construct answer from bits. | O(log(n)) |
9797
| 191 | BF | Straighforward. | O(log(n)) |
98+
| 198 | DP | DP[i] = max(DP[i-2]+nums[i], DP[i-1]). | O(n) |
99+
| 200 | DFS | Do DFS whenever you encounter a 1; #islands = # of times the DFS routine is called from main(). | O(n*m) |
100+
| 202 | Set | Use a set to keep track of all visited numbers. | Don't know. |
101+
| 205 | Hash | Make sure you have a 1-1 mapping. | O(n) |
102+
| 206 | BF | Use variables prevNode, curNode, nextNode. You need to do it this step by step, decide in how to and in what order to set the said variables. | O(n) |
103+
| 207 | DFS | You're looking for a loop. So set the nodes whom you're visiting in the current loop as gray, and if you end up visiting a gray node then there is a loop. | O(|V|+|E|) |
104+
| 208 | Tree | Multiway tree. | O(n) for both search and insert, n = # letters |
98105
| 413 | Array | [1, 2, 3, 4, 5, 7, 9, 11]. can be written as [5, 3] i.e. 5 sequence of difference 1 and 3 sequence of difference 2, you need to figure out how many parts you can split 5 and 3 into. | O(n) |
99106
| 694 | DFS | Keep track of the directions in which DFS proceeds in some form, maybe a string like ddr for down down right. | O(rows*cols) |
100107
| 738 | Array | Find the first time Xi > Xi+1, Xi -= 1 and turn all Xi+k = 9, For eg, 321 becomes 299. Figure out cases like 33332. | O(n) |

Solutions/198-HouseRobber.cpp

+4-9
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,15 @@ class Solution {
1111
if(len == 0) return 0;
1212
if(len == 1) return nums[0];
1313
if(len == 2) return max(nums[1], nums[0]);
14-
if(len == 3) return max(nums[1], nums[2]+nums[0]);
1514

1615
dp[0] = nums[0];
1716
dp[1] = max(nums[0], nums[1]);
18-
dp[2] = max(nums[1], nums[2]+nums[0]);
1917

20-
for(int i = 3; i < len; i++){
21-
dp[i] = max(dp[i-3], dp[i-2]) + nums[i];
22-
}
23-
int maxval = 0;
24-
for(int i = 0; i < len; i++){
25-
if(maxval < dp[i]) maxval = dp[i];
18+
for(int i = 2; i < len; i++){
19+
dp[i] = max(dp[i-2] + nums[i], dp[i-1]);
2620
}
2721

28-
return maxval;
22+
23+
return dp[len-1];
2924
}
3025
};

0 commit comments

Comments
 (0)