-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
189 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
docs/algorithm/2520.count-the-digits-that-divide-a-number.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# 2520. 统计能整除数字的位数 | ||
|
||
> 难度:<span style="color: #00af9b; font-weight: 500">简单</span> | ||
> | ||
> 地址:https://leetcode.cn/problems/count-the-digits-that-divide-a-number/description/ | ||
给你一个整数 `num` ,返回 `num` 中能整除 `num` 的数位的数目。 | ||
|
||
如果满足 `nums % val == 0` ,则认为整数 `val` 可以整除 `nums` 。 | ||
|
||
**示例 1:** | ||
|
||
> **<font color=#000>输入</font>**:num = 7 | ||
> | ||
> **<font color=#000>输出</font>**:1 | ||
> | ||
> **<font color=#000>解释</font>**:7 被自己整除,因此答案是 1 。 | ||
**示例 2:** | ||
|
||
> **<font color=#000>输入</font>**:num = 121 | ||
> | ||
> **<font color=#000>输出</font>**:2 | ||
> | ||
> **<font color=#000>解释</font>**:121 可以被 1 整除,但无法被 2 整除。由于 1 出现两次,所以返回 2 。 | ||
**示例 3:** | ||
|
||
> **<font color=#000>输入</font>**:num = 1248 | ||
> | ||
> **<font color=#000>输出</font>**:4 | ||
> | ||
> **<font color=#000>解释</font>**:1248 可以被它每一位上的数字整除,因此答案是 4 。 | ||
**提示:** | ||
|
||
- `1 <= num <= 10^9` | ||
- `num` 的数位中不含 `0` | ||
|
||
**题解:** | ||
|
||
```js | ||
/** | ||
* @param {number} num | ||
* @return {number} | ||
*/ | ||
var countDigits = function (num) { | ||
const str = num.toString(); | ||
let ans = 0; | ||
for (let i = 0; i < str.length; i++) { | ||
if (num % str[i] == 0) { | ||
ans += 1; | ||
} | ||
} | ||
return ans; | ||
}; | ||
``` | ||
|
||
或者 | ||
|
||
```js | ||
/** | ||
* @param {number} num | ||
* @return {number} | ||
*/ | ||
var countDigits = function (num) { | ||
let t = num; | ||
let ans = 0; | ||
while (t) { | ||
if (num % (t % 10) == 0) { | ||
ans += 1; | ||
} | ||
t = Math.floor(t / 10); | ||
} | ||
return ans; | ||
}; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
docs/algorithm/2698.find-the-punishment-number-of-an-integer.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# 2698. 求一个整数的惩罚数 | ||
|
||
> 难度:<span style="color: #ffb800; font-weight: 500">中等</span> | ||
> | ||
> 地址:https://leetcode.cn/problems/find-the-punishment-number-of-an-integer/ | ||
给你一个正整数 `n` ,请你返回 `n` 的 **惩罚数** 。 | ||
|
||
`n` 的 **惩罚数** 定义为所有满足以下条件 `i` 的数的平方和: | ||
|
||
- `1 <= i <= n` | ||
- `i * i` 的十进制表示的字符串可以分割成若干连续子字符串,且这些子字符串对应的整数值之和等于 i 。 | ||
|
||
**示例 1:** | ||
|
||
> **<font color=#000>输入</font>**:n = 10 | ||
> | ||
> **<font color=#000>输出</font>**:182 | ||
> | ||
> **<font color=#000>解释</font>**:总共有 3 个整数 i 满足要求: | ||
> \- 1 ,因为 1 \* 1 = 1 | ||
> \- 9 ,因为 9 \* 9 = 81 ,且 81 可以分割成 8 + 1 。 | ||
> \- 10 ,因为 10 \* 10 = 100 ,且 100 可以分割成 10 + 0 。 | ||
> 因此,10 的惩罚数为 1 + 81 + 100 = 182 | ||
**示例 2:** | ||
|
||
> **<font color=#000>输入</font>**:n = 37 | ||
> | ||
> **<font color=#000>输出</font>**:1478 | ||
> | ||
> **<font color=#000>解释</font>**:总共有 4 个整数 i 满足要求: | ||
> \- 1 ,因为 1 \* 1 = 1 | ||
> \- 9 ,因为 9 \* 9 = 81 ,且 81 可以分割成 8 + 1 。 | ||
> \- 10 ,因为 10 \* 10 = 100 ,且 100 可以分割成 10 + 0 。 | ||
> \- 36 ,因为 36 \* 36 = 1296 ,且 1296 可以分割成 1 + 29 + 6 。 | ||
> 因此,37 的惩罚数为 1 + 81 + 100 + 1296 = 1478 | ||
**提示:** | ||
|
||
- `1 <= n <= 1000` | ||
|
||
**题解:** | ||
|
||
![idea](../public/algorithm/idea.png) | ||
|
||
```js | ||
/** | ||
* @param {number} n | ||
* @return {number} | ||
*/ | ||
var punishmentNumber = function (n) { | ||
const dfs = (s, pos, tot, target) => { | ||
if (pos == s.length) { | ||
return tot == target; | ||
} | ||
let sum = 0; | ||
for (let i = pos; i < s.length; i++) { | ||
sum = sum * 10 + parseInt(s[i]); | ||
if (tot + sum > target) { | ||
break; | ||
} | ||
if (dfs(s, i + 1, tot + sum, target)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; | ||
let ans = 0; | ||
for (let i = 1; i <= n; i++) { | ||
let s = (i * i).toString(); | ||
if (dfs(s, 0, 0, i)) { | ||
ans += i * i; | ||
} | ||
} | ||
return ans; | ||
}; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# 【头条】React Hooks 如何替代或部分替代 redux 功能 | ||
|
||
我们把全局 store 分为两块 | ||
|
||
1. 从服务器端来,如各种 `model`,此时可以使用 `swr` 直接替代。或者封装一个 `useModel`,如 `useUser`、`usePermission`; | ||
|
||
2. 客户端全局 store,此时可以使用 `useReducer` 和 useCo`ntext 来替代。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# 【阿里】fetch 中 credentials 指什么意思,可以取什么值 | ||
|
||
`credentials` 指在使用 `fetch` 发送请求时是否应当发送 `cookie`。 | ||
|
||
- `omit`:从不发送 `cookie` | ||
- `same-origin`:同源时发送 `cookie`(浏览器默认值) | ||
- `include`:同源与跨域都发送 `cookie` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.