Skip to content

Commit 46b71e1

Browse files
committedJan 17, 2021
week13: add three js solution
1 parent 1708205 commit 46b71e1

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed
 

‎README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
|501|[Find Mode In Binary Search Tree](https://leetcode.com/problems/find-mode-in-binary-search-tree/) | [java](./algorithms/findModeInBST/Solution.java) |Easy|
100100
|477|[Total Hamming Distance](https://leetcode.com/problems/total-hamming-distance/) | |Medium|
101101
|463|[Island Perimeter](https://leetcode.com/problems/island-perimeter/) | |Easy|
102+
|455|[Assign Cookies](https://leetcode.com/problems/assign-cookies/) | [js](./algorithms/assignCookies/Solution.js) |Medium|
102103
|450|[NodeInABST](https://leetcode.com/problems/-node-in-a-bst/) | |Medium|
103104
|449|[Serialize and Deserialize BST](https://leetcode.com/problems/serialize-and-deserialize-bst/) | |Medium|
104105
|438|[Find all Anagrams in a string](https://leetcode.com/problems/find-all-anagrams-in-a-string/) | |Medium|
@@ -248,7 +249,7 @@
248249
|201|[Bitwise AND of Numbers Range](https://leetcode.com/problems/bitwise-and-of-numbers-range/)| |Medium|
249250
|200|[Number of Islands](https://leetcode.com/problems/number-of-islands/)| |Medium|
250251
|199|[Binary Tree Right Side View](https://leetcode.com/problems/binary-tree-right-side-view/)| |Medium|
251-
|198|[House Robber](https://leetcode.com/problems/house-robber/)| |Easy|
252+
|198|[House Robber](https://leetcode.com/problems/house-robber/)| [js](./algorithms/houseRobber/Solution.js) |Easy|
252253
|197|[Rising Temperature](https://leetcode.com/problems/rising-temperature/)| [Mysql](./algorithms/risingTemperature/Solution.sql) |Easy|
253254
|196|[Delete Duplicate Emails](https://leetcode.com/problems/delete-duplicate-emails/)| [Mysql](./algorithms/deleteDuplicateEmails/Solution.sql) |Easy|
254255
|191|[Number of 1 Bits](https://leetcode.com/problems/number-of-1-bits/)| [java](./algorithms/numberof1bits/Solution.java) |Easy|
@@ -318,7 +319,7 @@
318319
|125|[Valid Palindrome](https://leetcode.com/problems/valid-palindrome/)| |Easy|
319320
|124|[Binary Tree Maximum Path Sum](https://leetcode.com/problems/binary-tree-maximum-path-sum/)| |Hard|
320321
|123|[Best Time to Buy and Sell Stock III](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iii/)| |Hard|
321-
|122|[Best Time to Buy and Sell Stock II](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/)| |Medium|
322+
|122|[Best Time to Buy and Sell Stock II](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/)| [js](./algorithms/bestTimeToBuyAndSellStockIi/Solution.js) |Medium|
322323
|121|[Best Time to Buy and Sell Stock](https://leetcode.com/problems/best-time-to-buy-and-sell-stock/)| |Medium|
323324
|120|[Triangle](https://leetcode.com/problems/triangle/)| |Medium|
324325
|119|[Pascal's Triangle II](https://leetcode.com/problems/pascals-triangle-ii/)| |Easy|

‎algorithms/assignCookies/Solution.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
var findContentChildren = function(g, s) {
2+
const sortFunc = (a, b) => a - b;
3+
g.sort(sortFunc);
4+
s.sort(sortFunc);
5+
let i = 0;
6+
s.forEach(n => {
7+
if ( n >= g[i]) {
8+
i++;
9+
}
10+
});
11+
return i;
12+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
var maxProfit = function(prices) {
2+
let profit = 0;
3+
for (let i = 1; i < prices.length; i++) {
4+
if (prices[i] > prices[i - 1]) {
5+
profit += prices[i] - prices[i - 1];
6+
}
7+
}
8+
return profit;
9+
};

‎algorithms/houseRobber/Solution.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
var rob = function(nums) {
2+
if ( nums.length === 0) return 0;
3+
let dp0 = 0;
4+
let dp1 = nums[0];
5+
for ( let i = 2; i <= nums.length; i++) {
6+
const dp2 = Math.max(dp0 + nums[i - 1], dp1);
7+
dp0 = dp1;
8+
dp1 = dp2;
9+
}
10+
return dp1;
11+
};

0 commit comments

Comments
 (0)
Please sign in to comment.