Skip to content

Commit cfe0fb6

Browse files
updating all READMEs
1 parent 2da4aa9 commit cfe0fb6

File tree

10 files changed

+501
-19
lines changed

10 files changed

+501
-19
lines changed

.dev/logs.json

+20-10
Original file line numberDiff line numberDiff line change
@@ -1473,8 +1473,10 @@
14731473
"sols": {}
14741474
},
14751475
"326": {
1476-
"len": 0,
1477-
"sols": {}
1476+
"len": 2,
1477+
"sols": {
1478+
"power_of_three.rs": "a411e448082c6f9a00e1f3e673b30765e78d2402495ac34f01a736b698e3f5dc"
1479+
}
14781480
},
14791481
"327": {
14801482
"len": 0,
@@ -1523,8 +1525,10 @@
15231525
}
15241526
},
15251527
"338": {
1526-
"len": 0,
1527-
"sols": {}
1528+
"len": 2,
1529+
"sols": {
1530+
"counting_bits.rs": "810d9baf66015fbbb84cfdfdd77984a2da6dac850329d83d624ac6eb17167a5f"
1531+
}
15281532
},
15291533
"339": {
15301534
"len": 0,
@@ -1539,8 +1543,10 @@
15391543
"sols": {}
15401544
},
15411545
"342": {
1542-
"len": 0,
1543-
"sols": {}
1546+
"len": 2,
1547+
"sols": {
1548+
"power_of_four.rs": "de8881cbb1ecb0da127d1418aa699232356bb3f463917f087493fd9267b59e7f"
1549+
}
15441550
},
15451551
"343": {
15461552
"len": 0,
@@ -1553,8 +1559,10 @@
15531559
}
15541560
},
15551561
"345": {
1556-
"len": 0,
1557-
"sols": {}
1562+
"len": 2,
1563+
"sols": {
1564+
"reverse_vowels_of_a_string.rs": "bebf5b4ea69ac9e4a60dfc84ce0a98a6d10d53318bfdb4461fc44e769b348bf8"
1565+
}
15581566
},
15591567
"346": {
15601568
"len": 0,
@@ -2193,8 +2201,10 @@
21932201
"sols": {}
21942202
},
21952203
"502": {
2196-
"len": 0,
2197-
"sols": {}
2204+
"len": 2,
2205+
"sols": {
2206+
"Ipo.java": "28d55d9801505fe82e672eeb60112de6376568d8be68d5639a8ac12520e2f3af"
2207+
}
21982208
},
21992209
"503": {
22002210
"len": 0,

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
[**_Rejection Sampling_**][rejection sampling]   
9696
[**_Biconnected Component_**][biconnected component]
9797

98-
### **Total Problems Solved: _121_**
98+
### **Total Problems Solved: _126_**
9999

100100
---
101101

TOPICWISE.md

+24-7
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
| **0300** | [Longest Increasing Subsequence][300] | Array, Binary Search, DP | ![][medium] | |
4848
| **0322** | [Coin Change][322] | Array, DP, BFS | ![][medium] | |
4949
| **0442** | [Find All Duplicates][442] | Array, Hash Table | ![][medium] | |
50+
| **0502** | [IPO][502] | Array, Greedy, Sorting, Heap (Priority Queue) | ![][hard] | |
5051
| **0506** | [Relative Ranks][506] | Array, Sorting, Heap | ![][easy] | |
5152
| **0518** | [Coin Change 2][518] | Array, DP | ![][medium] | |
5253
| **0540** | [Single Element in a Sorted Array][540] | Array, BS | ![][medium] | |
@@ -82,6 +83,7 @@
8283
| **0257** | [Binary Tree Paths][257] | String, Backtracking, Tree, Depth-First Search, Binary Tree | ![][easy] | |
8384
| **0290** | [Word Pattern][290] | Hash Table, String | ![][easy] | |
8485
| **0344** | [Reverse String][344] | Two Pointers, String, Recursion | ![][easy] | |
86+
| **0345** | [Reverse Vowels of a String][345] | 2P, String | ![][easy] | |
8587
| **0389** | [Find the Difference][389] | Hash Table, String, Bit Manipulation, Sorting | ![][easy] | |
8688
| **0438** | [Find All Anagrams in a String][438] | Hash Table, String, Sliding Window | ![][medium] | |
8789
| **0516** | [Longest Palindromic Subsequence][516] | String, DP | ![][medium] | |
@@ -138,6 +140,7 @@
138140
| **0300** | [Longest Increasing Subsequence][300] | Array, Binary Search, DP | ![][medium] | |
139141
| **0322** | [Coin Change][322] | Array, DP, BFS | ![][medium] | |
140142
| **0337** | [House Robber III][337] | DP, Tree, DFS, Binary Tree | ![][medium] | |
143+
| **0338** | [Counting Bits][338] | DP, Bit Manip | ![][easy] | |
141144
| **0509** | [Fibonacci Number][509] | Math, Recursion, DP, Memoization | ![][easy] | |
142145
| **0516** | [Longest Palindromic Subsequence][516] | String, DP | ![][medium] | |
143146
| **0518** | [Coin Change 2][518] | Array, DP | ![][medium] | |
@@ -166,6 +169,8 @@
166169
| **0263** | [Ugly Number][263] | Math | ![][easy] | |
167170
| **0268** | [Missing Number][268] | Array, Hash Table, Math, BS, Bit Manip, Sorting | ![][easy] | |
168171
| **0292** | [Nim Game][292] | Math, Brainteaser, Game Theory | ![][easy] | |
172+
| **0326** | [Power of Three][326] | Math, Recursion | ![][easy] | |
173+
| **0342** | [Power of Four][342] | Math, Bit Manip, Recursion | ![][easy] | |
169174
| **0367** | [Valid Perfect Square][367] | Math, Binary Search | ![][easy] | |
170175
| **0445** | [Add Two Numbers II][445] | Linked List, Math, Stack | ![][medium] | |
171176
| **0509** | [Fibonacci Number][509] | Math, Recursion, DP, Memoization | ![][easy] | |
@@ -185,6 +190,7 @@
185190
| **0242** | [Valid Anagram][242] | Hash Table, String, Sorting | ![][easy] | |
186191
| **0268** | [Missing Number][268] | Array, Hash Table, Math, BS, Bit Manip, Sorting | ![][easy] | |
187192
| **0389** | [Find the Difference][389] | Hash Table, String, Bit Manipulation, Sorting | ![][easy] | |
193+
| **0502** | [IPO][502] | Array, Greedy, Sorting, Heap (Priority Queue) | ![][hard] | |
188194
| **0506** | [Relative Ranks][506] | Array, Sorting, Heap | ![][easy] | |
189195
| **0888** | [Fair Candy Swap][888] | Array, Hash Table, Binary Search, Sorting | ![][easy] | |
190196
| **1498** | [Number of Subsequences That Satisfy the Given Sum Condition][1498] | Array, 2P, BS, Sorting | ![][medium] | |
@@ -213,13 +219,14 @@
213219

214220
## Greedy
215221

216-
| # | Solution | Tags | Difficulty | Remark |
217-
| :------: | :---------------------------------------: | :----------------------------: | :---------: | :----: |
218-
| **0055** | [Jump Game][55] | Array, DP, Greedy | ![][medium] | |
219-
| **0094** | [Binary Tree Inorder Traversal][94] | Stack, Tree, DFS, Binary Tree | ![][easy] | |
220-
| **0098** | [Validate Binary Search Tree][98] | Tree, DFS, BST, Binary Tree | ![][medium] | |
221-
| **0122** | [Best Time to Buy and Sell Stock II][122] | Array, DP, Greedy | ![][medium] | |
222-
| **1537** | [Get the Maximum Score][1537] | Array, Two Pointer, DP, Greedy | ![][hard] | |
222+
| # | Solution | Tags | Difficulty | Remark |
223+
| :------: | :---------------------------------------: | :-------------------------------------------: | :---------: | :----: |
224+
| **0055** | [Jump Game][55] | Array, DP, Greedy | ![][medium] | |
225+
| **0094** | [Binary Tree Inorder Traversal][94] | Stack, Tree, DFS, Binary Tree | ![][easy] | |
226+
| **0098** | [Validate Binary Search Tree][98] | Tree, DFS, BST, Binary Tree | ![][medium] | |
227+
| **0122** | [Best Time to Buy and Sell Stock II][122] | Array, DP, Greedy | ![][medium] | |
228+
| **0502** | [IPO][502] | Array, Greedy, Sorting, Heap (Priority Queue) | ![][hard] | |
229+
| **1537** | [Get the Maximum Score][1537] | Array, Two Pointer, DP, Greedy | ![][hard] | |
223230

224231
<!---------------------------------{ Solution Table }-------------------------->
225232

@@ -352,6 +359,7 @@
352359
| **0234** | [Palindrome Linked List][234] | LL, 2P, ST, Recursion | ![][easy] | |
353360
| **0283** | [Move Zeroes][283] | Array, Two Pointers | ![][easy] | |
354361
| **0344** | [Reverse String][344] | Two Pointers, String, Recursion | ![][easy] | |
362+
| **0345** | [Reverse Vowels of a String][345] | 2P, String | ![][easy] | |
355363
| **0541** | [Reverse String II][541] | Two Pointers, String | ![][easy] | |
356364
| **0653** | [Two Sum IV - Input is a BST ][653] | Tree, DFS, BST, Binary Tree | ![][easy] | |
357365
| **0876** | [Middle of the Linked List][876] | Linked List, Two Pointers | ![][easy] | |
@@ -370,6 +378,8 @@
370378
| **0191** | [Number of 1 Bits][191] | Divide & Conquer, Bit Manipulation | ![][easy] | |
371379
| **0231** | [Power of Two][231] | Math, Bit Manipulation, Recursion | ![][easy] | |
372380
| **0268** | [Missing Number][268] | Array, Hash Table, Math, BS, Bit Manip, Sorting | ![][easy] | |
381+
| **0338** | [Counting Bits][338] | DP, Bit Manip | ![][easy] | |
382+
| **0342** | [Power of Four][342] | Math, Bit Manip, Recursion | ![][easy] | |
373383
| **0389** | [Find the Difference][389] | Hash Table, String, Bit Manipulation, Sorting | ![][easy] | |
374384
| **1461** | [Check If a String Contains All Binary Codes of Size K][1461] | String, Hash Table, Bit Manipulation | ![][medium] | |
375385

@@ -517,6 +527,8 @@
517527
| **0206** | [Reverse Linked List][206] | Linked List, Recursion | ![][easy] | |
518528
| **0231** | [Power of Two][231] | Math, Bit Manipulation, Recursion | ![][easy] | |
519529
| **0234** | [Palindrome Linked List][234] | LL, 2P, ST, Recursion | ![][easy] | |
530+
| **0326** | [Power of Three][326] | Math, Recursion | ![][easy] | |
531+
| **0342** | [Power of Four][342] | Math, Bit Manip, Recursion | ![][easy] | |
520532
| **0344** | [Reverse String][344] | Two Pointers, String, Recursion | ![][easy] | |
521533
| **0509** | [Fibonacci Number][509] | Math, Recursion, DP, Memoization | ![][easy] | |
522534

@@ -919,8 +931,12 @@
919931
[292]: ./src/0201-0300/292%20-%20Nim%20Game/
920932
[300]: ./src/0201-0300/300%20-%20Longest%20Increasing%20Subsequence/
921933
[322]: ./src/0301-0400/322%20-%20Coin%20Change/
934+
[326]: ./src/0301-0400/326%20-%20Power%20Of%20Three/
922935
[337]: ./src/0301-0400/337%20-%20House%20Robber%20III/
936+
[338]: ./src/0301-0400/338%20-%20Counting%20Bits/
937+
[342]: ./src/0301-0400/342%20-%20Power%20of%20Four/
923938
[344]: ./src/0301-0400/344%20-%20Reverse%20String/
939+
[345]: ./src/0301-0400/345%20-%20Reverse%20Vowels%20of%20a%20String/
924940
[367]: ./src/0301-0400/367%20-%20Valid%20Perfect%20Square/
925941
[369]: ./src/0301-0400/369%20-%20Plus%20One%20Linked%20List/
926942
[387]: ./src/0301-0400/387%20-%20First%20Unique%20Character%20in%20a%20String/
@@ -929,6 +945,7 @@
929945
[442]: ./src/0401-0500/442%20-%20Find%20All%20Duplicates%20in%20an%20Array/
930946
[445]: ./src/0401-0500/445%20-%20Add%20Two%20Numbers%20II/
931947
[461]: ./src/0401-0500/461%20-%20Hamming%20Distance/
948+
[502]: ./src/0501-0600/502%20-%20IPO/
932949
[506]: ./src/0501-0600/506%20-%20%20Relative%20Ranks/
933950
[509]: ./src/0501-0600/509%20-%20Fibonacci%20Number/
934951
[516]: ./src/0501-0600/516%20-%20Longest%20Palindromic%20Subsequence/

docs/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ It might take some time to reflect changes from the repository.
103103
[**_Rejection Sampling_**][rejection sampling] &nbsp;&nbsp;
104104
[**_Biconnected Component_**][biconnected component]
105105

106-
### **Total Problems Solved: _121_**
106+
### **Total Problems Solved: _126_**
107107

108108
## Contributors
109109

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# 326. Power Of Three [![share]](https://leetcode.com/problems/power-of-three/)
2+
3+
![][easy]
4+
5+
## Problem Statement
6+
7+
<p>Given an integer <code>n</code>, return <em><code>true</code> if it is a power of three. Otherwise, return <code>false</code></em>.</p>
8+
<p>An integer <code>n</code> is a power of three, if there exists an integer <code>x</code> such that <code>n == 3<sup>x</sup></code>.</p>
9+
<p> </p>
10+
<p><strong class="example">Example 1:</strong></p>
11+
12+
```
13+
Input: n = 27
14+
Output: true
15+
Explanation: 27 = 33
16+
```
17+
18+
<p><strong class="example">Example 2:</strong></p>
19+
20+
```
21+
Input: n = 0
22+
Output: false
23+
Explanation: There is no x where 3x = 0.
24+
```
25+
26+
<p><strong class="example">Example 3:</strong></p>
27+
28+
```
29+
Input: n = -1
30+
Output: false
31+
Explanation: There is no x where 3x = (-1).
32+
```
33+
34+
<p> </p>
35+
<p><strong>Constraints:</strong></p>
36+
<ul>
37+
<li><code>-2<sup>31</sup> &lt;= n &lt;= 2<sup>31</sup> - 1</code></li>
38+
</ul>
39+
<p> </p>
40+
<strong>Follow up:</strong> Could you solve it without loops/recursion?
41+
42+
## Solutions
43+
44+
### [_Rust_](power_of_three.rs)
45+
46+
```rs [Rust]
47+
impl Solution {
48+
pub fn is_power_of_three(n: i32) -> bool {
49+
if n <= 0 {
50+
return false;
51+
}
52+
53+
let mut n = n;
54+
while n % 3 == 0 {
55+
n /= 3;
56+
}
57+
58+
n == 1
59+
}
60+
}
61+
62+
```
63+
64+
### [_..._]()
65+
66+
```
67+
68+
```
69+
70+
<!----------------------------------{ link }--------------------------------->
71+
72+
[share]: https://graph.org/file/3ea5234dda646b71c574a.png
73+
[easy]: https://img.shields.io/badge/Difficulty-Easy-bright.svg
74+
[medium]: https://img.shields.io/badge/Difficulty-Medium-yellow.svg
75+
[hard]: https://img.shields.io/badge/Difficulty-Hard-red.svg
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# 338. Counting Bits [![share]](https://leetcode.com/problems/counting-bits/)
2+
3+
![][easy]
4+
5+
## Problem Statement
6+
7+
<p>Given an integer <code>n</code>, return <em>an array </em><code>ans</code><em> of length </em><code>n + 1</code><em> such that for each </em><code>i</code><em> </em>(<code>0 &lt;= i &lt;= n</code>)<em>, </em><code>ans[i]</code><em> is the <strong>number of </strong></em><code>1</code><em><strong>'s</strong> in the binary representation of </em><code>i</code>.</p>
8+
<p> </p>
9+
<p><strong class="example">Example 1:</strong></p>
10+
11+
```
12+
Input: n = 2
13+
Output: [0,1,1]
14+
Explanation:
15+
0 --&gt; 0
16+
1 --&gt; 1
17+
2 --&gt; 10
18+
```
19+
20+
<p><strong class="example">Example 2:</strong></p>
21+
22+
```
23+
Input: n = 5
24+
Output: [0,1,1,2,1,2]
25+
Explanation:
26+
0 --&gt; 0
27+
1 --&gt; 1
28+
2 --&gt; 10
29+
3 --&gt; 11
30+
4 --&gt; 100
31+
5 --&gt; 101
32+
```
33+
34+
<p> </p>
35+
<p><strong>Constraints:</strong></p>
36+
<ul>
37+
<li><code>0 &lt;= n &lt;= 10<sup>5</sup></code></li>
38+
</ul>
39+
<p> </p>
40+
<p><strong>Follow up:</strong></p>
41+
<ul>
42+
<li>It is very easy to come up with a solution with a runtime of <code>O(n log n)</code>. Can you do it in linear time <code>O(n)</code> and possibly in a single pass?</li>
43+
<li>Can you do it without using any built-in function (i.e., like <code>__builtin_popcount</code> in C++)?</li>
44+
</ul>
45+
46+
<details>
47+
<summary>
48+
49+
#### _Click to open Hints_
50+
51+
</summary>
52+
53+
- You should make use of what you have produced already.
54+
- Divide the numbers in ranges like [2-3], [4-7], [8-15] and so on. And try to generate new range from previous.
55+
- Or does the odd/even status of the number help you in calculating the number of 1s?
56+
57+
</details>
58+
59+
## Solutions
60+
61+
### [_Rust_](counting_bits.rs)
62+
63+
```rs [Rust]
64+
impl Solution {
65+
pub fn count_bits(n: i32) -> Vec<i32> {
66+
let mut res = vec![0; n as usize + 1];
67+
68+
for i in 1..=n {
69+
let i = i as usize;
70+
// let i_and_i_minus_1 = i & (i - 1);
71+
// res[i] = res[i_and_i_minus_1] + 1;
72+
res[i] = res[i >> 1] + (i & 1) as i32;
73+
}
74+
75+
res
76+
}
77+
}
78+
79+
```
80+
81+
### [_..._]()
82+
83+
```
84+
85+
```
86+
87+
<!----------------------------------{ link }--------------------------------->
88+
89+
[share]: https://graph.org/file/3ea5234dda646b71c574a.png
90+
[easy]: https://img.shields.io/badge/Difficulty-Easy-bright.svg
91+
[medium]: https://img.shields.io/badge/Difficulty-Medium-yellow.svg
92+
[hard]: https://img.shields.io/badge/Difficulty-Hard-red.svg

0 commit comments

Comments
 (0)