Movatterモバイル変換


[0]ホーム

URL:


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

Commite89b64e

Browse files
author
luzhipeng
committed
1 parentc25465e commite89b64e

11 files changed

+134
-6
lines changed

‎172.factorial-trailing-zeroes.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
*@lc app=leetcode id=172 lang=javascript
3+
*
4+
* [172] Factorial Trailing Zeroes
5+
*/
6+
/**
7+
*@param {number} n
8+
*@return {number}
9+
*/
10+
vartrailingZeroes=function(n){
11+
// tag: 数论
12+
// 只有 2 和 5 相乘才等于 10
13+
// if (n === 0) return n;
14+
15+
// return Math.floor(n / 5) + trailingZeroes(Math.floor(n / 5));
16+
letcount=0;
17+
while(n>=5){
18+
count+=Math.floor(n/5);
19+
n=Math.floor(n/5);
20+
}
21+
returncount;
22+
};
23+

‎263.ugly-number.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
*@lc app=leetcode id=263 lang=javascript
3+
*
4+
* [263] Ugly Number
5+
*/
6+
/**
7+
*@param {number} num
8+
*@return {boolean}
9+
*/
10+
varisUgly=function(num){
11+
// TAG: 数论
12+
if(num<=0)returnfalse;
13+
if(num===1)returntrue;
14+
15+
constlist=[2,3,5];
16+
17+
if(list.includes(num))returntrue;
18+
19+
for(letioflist){
20+
if(num%i===0)returnisUgly(Math.floor(num/i));
21+
}
22+
returnfalse;
23+
};

‎342.power-of-four.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
*@lc app=leetcode id=342 lang=javascript
3+
*
4+
* [342] Power of Four
5+
*/
6+
/**
7+
*@param {number} num
8+
*@return {boolean}
9+
*/
10+
varisPowerOfFour=function(num){
11+
// tag: 数论
12+
13+
// 100
14+
// 10000
15+
// 1000000
16+
17+
// 发现规律: 4的幂次方的二进制表示 1 的位置都是在奇数位(且不在最低位),其他位置都为0
18+
19+
// 10
20+
// 100
21+
// 1000
22+
23+
// 发现规律: 2的幂次方的特点是最低位之外,其他位置有且仅有一个1
24+
25+
// 如果满足:
26+
// 1. 是 2 的幂次方, 就能保证最低位之外,其他位置有且仅有一个1
27+
// 我们还需要保证
28+
// 2. 这个1不再偶数位置,一定在奇数位置就行了
29+
30+
// 我们可以取一个特殊数字,这个特殊数字,奇数位置都是1,偶数位置都是0,然后和这个特殊数字
31+
// `求与`, 如果等于本身,那么毫无疑问,这个1不再偶数位置,一定在奇数位置
32+
// 因为如果在偶数位置,`求与`的结果就是0了
33+
// 特殊的数字:
34+
35+
// 01010101010101010101010101010101
36+
37+
if(num===1)returntrue;
38+
if(num<4)returnfalse;
39+
40+
if((num&(num-1))!==0)returnfalse;
41+
42+
return(num&0x55555555)===num;
43+
};

‎575.distribute-candies.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
*@lc app=leetcode id=575 lang=javascript
3+
*
4+
* [575] Distribute Candies
5+
*/
6+
/**
7+
*@param {number[]} candies
8+
*@return {number}
9+
*/
10+
vardistributeCandies=function(candies){
11+
constcount=newSet(candies);
12+
returnMath.min(count.size,candies.length>>1);
13+
};
14+

‎README.en.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,12 @@ Latest updated flashcards (only lists the front page):
201201
- The thinkings and related problems of double-pointers problems?
202202
- The thinkings and related problems of sliding window problems?
203203
- The thinkings and related problems of backtracking?
204+
- The thinkings and related problems of number theory?
205+
- The thinkings and related problems of bit operations?
206+
207+
>WIP: the translation of the flashcards are on the way.
208+
209+
>problems added:#2#3#11
204210
205211

206212

‎README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,15 @@ anki - 文件 - 导入 - 下拉格式选择“打包的 anki集合”,然后
194194

195195
目前已更新卡片一览(仅列举正面):
196196

197-
- 二分法解决问题的关键点是什么,相关问题有哪些
197+
- 二分法解决问题的关键点是什么,相关问题有哪些?
198198
- 如何用栈的特点来简化操作, 涉及到的题目有哪些?
199199
- 双指针问题的思路以及相关题目有哪些?
200200
- 滑动窗口问题的思路以及相关题目有哪些?
201201
- 回溯法解题的思路以及相关题目有哪些?
202+
- 数论解决问题的关键点是什么,相关问题有哪些?
203+
- 位运算解决问题的关键点是什么,相关问题有哪些?
204+
205+
>已加入的题目有:#2#3#11
202206
203207
###计划
204208

‎backlog/338.counting-bits.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,22 @@
4444
*@return {number[]}
4545
*/
4646
varcountBits=function(num){
47-
// 这是一道位运算的题目
47+
// tag: bit dp
48+
// Time complexity: O(n)
49+
// Space complexity: O(n)
4850
constres=[];
4951
res[0]=0;
5052

53+
// 10000100110101
5154
for(leti=1;i<=num;i++){
52-
if((i&1)===0){// 偶数
53-
res[i]=res[i>>1];// 偶数不影响结果
54-
}else{// 奇数
55-
res[i]=res[i-1]+1;// 如果是奇数,那就是前面的数字 + 1
55+
if((i&1)===0){
56+
// 偶数
57+
// 偶数最后一位是0,因此右移一位对结果没有影响
58+
res[i]=res[i>>1];
59+
}else{
60+
// 奇数
61+
// 奇数最后一位是1,i - 1 的 位数 + 1 就是结果
62+
res[i]=res[i-1]+1;
5663
}
5764
}
5865

‎problems/136.single-number.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ Your algorithm should have a linear runtime complexity. Could you implement it w
3232

3333
3. 很多人只是记得异或的性质和规律,但是缺乏对其本质的理解,导致很难想到这种解法(我本人也没想到)
3434

35+
4. bit 运算
36+
3537
##代码
3638

3739
```js

‎problems/190.reverse-bits.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ eg :
5353

5454
3. 双"指针" 模型
5555

56+
4. bit 运算
57+
5658

5759
##代码
5860

‎problems/191.number-of-1-bits.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ In Java, the compiler represents the signed integers using 2's complement notati
4747

4848
1.`n & (n - 1)` 可以`消除` n 最后的一个1的原理 简化操作
4949

50+
2. bit 运算
51+
5052

5153
##代码
5254

‎problems/201.bitwise-and-of-numbers-range.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ Output: 0
6161

6262
- 可以用递归实现, 个人认为比较难想到
6363

64+
- bit 运算
65+
6466
代码:
6567

6668
```js

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp