Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7def024

Browse files
update
1 parent a1410f9 commit 7def024

File tree

4 files changed

+57
-13
lines changed

4 files changed

+57
-13
lines changed

‎CATEGORY.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,18 @@ https://garciparedes.me/#headers
5757

5858
- Dynamic Programming +7
5959

60-
- [ ] 357
6160
- [ ] 376
6261
- [ ] 1143
6362
- [ ] 5
6463
- [ ] 91
6564
- [ ] 152
66-
- [ ] 264
67-
- [ ] 279
68-
- [ ] 300
69-
- [ ] 309
70-
- [ ] 322
71-
- [ ] 343
65+
- [ ] 264
66+
- [ ] 279
67+
- [ ] 300
68+
- [ ] 309
69+
- [ ] 322
70+
- [ ] 343
71+
- [ ] 357
7272

7373
- Greedy
7474

‎src/264-ugly-number-ii/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// HELP:
22

3-
exportfunction nthUglyNumber(num) {
3+
function nthUglyNumber(num) {
44
let dp = [1];
5-
let [a,b,c] = [0, 0, 0];
5+
let [two,three,five] = [0, 0, 0];
66

77
for (let i = 1; i < num; i++) {
8-
dp[i] = Math.min(dp[a] * 2, dp[b] * 3, dp[c] * 5);
9-
if (dp[i] === dp[a] * 2) a++;
10-
if (dp[i] === dp[b] * 3) b++;
11-
if (dp[i] === dp[c] * 5) c++;
8+
dp[i] = Math.min(dp[two] * 2, dp[three] * 3, dp[five] * 5);
9+
if (dp[i] === dp[two] * 2) two++;
10+
if (dp[i] === dp[three] * 3) three++;
11+
if (dp[i] === dp[five] * 5) five++;
1212
}
1313

1414
return dp[num - 1];
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @param {number} n
3+
* @return {number}
4+
*/
5+
var countNumbersWithUniqueDigits = function (n) {
6+
if (n === 0) return 0;
7+
if (n === 1) return 10;
8+
const dp = [0, 10];
9+
for (let i = 2; i <= n; i++) {
10+
let sum = Array(i - 1)
11+
.fill(0)
12+
.reduce((acc, _, index) => acc * Math.max(9 - index, 1), 9);
13+
14+
dp[i] = dp[i - 1] + sum;
15+
}
16+
17+
return dp[n];
18+
};

‎src/91-decode-ways/20210722.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @param {string} s
3+
* @return {number}
4+
*/
5+
var numDecodings = function (s) {
6+
if (s === "0") return 0;
7+
let pre1 = 1;
8+
let pre2 = 0;
9+
let current = 0;
10+
11+
for (let i = 1; i <= s.length; i++) {
12+
current = 0;
13+
14+
if (s[i - 1] !== "0") {
15+
current += pre1;
16+
}
17+
if (s[i - 2] !== "0" && s[i - 2] * 10 + s[i - 1] * 1 <= 26) {
18+
current += pre2;
19+
}
20+
21+
pre2 = pre1;
22+
pre1 = current;
23+
}
24+
25+
return current;
26+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /