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 f7efba7

Browse files
updating docs
1 parent 6ca0b18 commit f7efba7

File tree

8 files changed

+467
-0
lines changed

8 files changed

+467
-0
lines changed

‎docs/.vitepress/Sidebar.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,10 +424,22 @@ export default Sidebar = [
424424
collapsible: true,
425425
collapsed: true,
426426
items: [
427+
{
428+
text: "401 - Binary Watch",
429+
link: "/solution/0401-0500/401 - Binary Watch.md",
430+
},
427431
{
428432
text: "404 - Sum of Left Leaves",
429433
link: "/solution/0401-0500/404 - Sum of Left Leaves.md",
430434
},
435+
{
436+
text: "412 - Fizz Buzz",
437+
link: "/solution/0401-0500/412 - Fizz Buzz.md",
438+
},
439+
{
440+
text: "414 - Third Maximum Number",
441+
link: "/solution/0401-0500/414 - Third Maximum Number.md",
442+
},
431443
{
432444
text: "438 - Find All Anagrams in a String",
433445
link: "/solution/0401-0500/438 - Find All Anagrams in a String.md",
@@ -643,6 +655,17 @@ export default Sidebar = [
643655
},
644656
],
645657
},
658+
{
659+
text: "2101-2200",
660+
collapsible: true,
661+
collapsed: true,
662+
items: [
663+
{
664+
text: "2176 - Count Equal and Divisible Pairs in an Array",
665+
link: "/solution/2101-2200/2176 - Count Equal and Divisible Pairs in an Array.md",
666+
},
667+
],
668+
},
646669
{
647670
text: "2201-2300",
648671
collapsible: true,
@@ -654,4 +677,15 @@ export default Sidebar = [
654677
},
655678
],
656679
},
680+
{
681+
text: "2401-2500",
682+
collapsible: true,
683+
collapsed: true,
684+
items: [
685+
{
686+
text: "2427 - Number of Common Factors",
687+
link: "/solution/2401-2500/2427 - Number of Common Factors.md",
688+
},
689+
],
690+
},
657691
];

‎docs/SERIALWISE.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,10 @@
112112
| **0387** | [First Unique Character in a String][387] | Hash Table, String, Queue, Counting | ![][easy] | |
113113
| **0389** | [Find the Difference][389] | Hash Table, String, Bit Manipulation, Sorting | ![][easy] | |
114114
| **0392** | [Is Subsequence][392] | Two Pointers, String, DP | ![][easy] | |
115+
| **0401** | [Binary Watch][401] | Backtracking, Bit Manip | ![][easy] | |
115116
| **0404** | [Sum of Left Leaves][404] | Tree, Depth-First Search, Breadth-First Search, Binary Tree | ![][easy] | |
117+
| **0412** | [Fizz Buzz][412] | Math, String, Simulation | ![][easy] | |
118+
| **0414** | [Third Maximum Number][414] | Array, Sorting | ![][easy] | |
116119
| **0438** | [Find All Anagrams in a String][438] | Hash Table, String, Sliding Window | ![][medium] | |
117120
| **0442** | [Find All Duplicates][442] | Array, Hash Table | ![][medium] | |
118121
| **0445** | [Add Two Numbers II][445] | Linked List, Math, Stack | ![][medium] | |
@@ -147,6 +150,7 @@
147150
| **1580** | [Shuffle the Array][1580] | Array | ![][easy] | |
148151
| **1630** | [Count Odd Numbers in an Interval Range][1630] | Math | ![][easy] | |
149152
| **1957** | [Delete Characters to Make Fancy String][1957] | String | ![][easy] | |
153+
| **2176** | [Count Equal and Divisible Pairs in an Array][2176] | Array | ![][easy] | |
150154
| **2236** | [Root Equal to Sum of Children][2236] | Tree, Binary Tree | ![][easy] | |
151155

152156
</div>
@@ -255,7 +259,10 @@
255259
[387]: ./solution/0301-0400/387%20-%20First%20Unique%20Character%20in%20a%20String.md
256260
[389]: ./solution/0301-0400/389%20-%20Find%20the%20Difference.md
257261
[392]: ./solution/0301-0400/392%20-%20Is%20Subsequence.md
262+
[401]: ./solution/0401-0500/401%20-%20Binary%20Watch.md
258263
[404]: ./solution/0401-0500/404%20-%20Sum%20of%20Left%20Leaves.md
264+
[412]: ./solution/0401-0500/412%20-%20Fizz%20Buzz.md
265+
[414]: ./solution/0401-0500/414%20-%20Third%20Maximum%20Number.md
259266
[438]: ./solution/0401-0500/438%20-%20Find%20All%20Anagrams%20in%20a%20String.md
260267
[442]: ./solution/0401-0500/442%20-%20Find%20All%20Duplicates%20in%20an%20Array.md
261268
[445]: ./solution/0401-0500/445%20-%20Add%20Two%20Numbers%20II.md
@@ -292,6 +299,7 @@
292299
[1580]: ./solution/1401-1500/1470%20-%20Shuffle%20the%20Array.md
293300
[1630]: ./solution/1501-1600/1523.%20Count%20Odd%20Numbers%20in%20an%20Interval%20Range.md
294301
[1957]: ./solution/1901-2000/1957%20-%20Delete%20Characters%20to%20Make%20Fancy%20String.md
302+
[2176]: ./solution/2101-2200/2176%20-%20Count%20Equal%20and%20Divisible%20Pairs%20in%20an%20Array.md
295303
[2236]: ./solution/2201-2300/2236%20-%20Root%20Equals%20Sum%20of%20Children.md
296304

297305
<!----------------------------------{ Labels }--------------------------------->

‎docs/TOPICWISE.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
| **0322** | [Coin Change][322] | Array, Dynamic Programming, BFS | ![][medium] | |
4949
| **0349** | [Intersection of Two Arrays][349] | Array, Hash Table, Two Pointers, Binary Search, Sorting | ![][easy] | |
5050
| **0350** | [Intersection of Two Arrays II][350] | Array, Hash Table, Two Pointers, Binary Search, Sorting | ![][easy] | |
51+
| **0414** | [Third Maximum Number][414] | Array, Sorting | ![][easy] | |
5152
| **0442** | [Find All Duplicates][442] | Array, Hash Table | ![][medium] | |
5253
| **0502** | [IPO][502] | Array, Greedy, Sorting, Heap (Priority Queue) | ![][hard] | |
5354
| **0506** | [Relative Ranks][506] | Array, Sorting, Heap | ![][easy] | |
@@ -65,6 +66,7 @@
6566
| **1498** | [Number of Subsequences That Satisfy the Given Sum Condition][1498] | Array, Two Pointers, Binary Search, Sorting | ![][medium] | |
6667
| **1537** | [Get the Maximum Score][1537] | Array, Two Pointer, Dynamic Programming, Greedy | ![][hard] | |
6768
| **1580** | [Shuffle the Array][1580] | Array | ![][easy] | |
69+
| **2176** | [Count Equal and Divisible Pairs in an Array][2176] | Array | ![][easy] | |
6870

6971
<!---------------------------------{ Solution Table }-------------------------->
7072

@@ -90,6 +92,7 @@
9092
| **0387** | [First Unique Character in a String][387] | Hash Table, String, Queue, Counting | ![][easy] | |
9193
| **0389** | [Find the Difference][389] | Hash Table, String, Bit Manipulation, Sorting | ![][easy] | |
9294
| **0392** | [Is Subsequence][392] | Two Pointers, String, DP | ![][easy] | |
95+
| **0412** | [Fizz Buzz][412] | Math, String, Simulation | ![][easy] | |
9396
| **0438** | [Find All Anagrams in a String][438] | Hash Table, String, Sliding Window | ![][medium] | |
9497
| **0516** | [Longest Palindromic Subsequence][516] | String, DP | ![][medium] | |
9598
| **0541** | [Reverse String II][541] | Two Pointers, String | ![][easy] | |
@@ -182,6 +185,7 @@
182185
| **0326** | [Power of Three][326] | Math, Recursion | ![][easy] | |
183186
| **0342** | [Power of Four][342] | Math, Bit Manipulation, Recursion | ![][easy] | |
184187
| **0367** | [Valid Perfect Square][367] | Math, Binary Search | ![][easy] | |
188+
| **0412** | [Fizz Buzz][412] | Math, String, Simulation | ![][easy] | |
185189
| **0445** | [Add Two Numbers II][445] | Linked List, Math, Stack | ![][medium] | |
186190
| **0509** | [Fibonacci Number][509] | Math, Recursion, Dynamic Programming, Memoization | ![][easy] | |
187191
| **1232** | [Check If It Is a Straight Line][1232] | Array, Math, Geometry | ![][easy] | |
@@ -202,6 +206,7 @@
202206
| **0349** | [Intersection of Two Arrays][349] | Array, Hash Table, Two Pointers, Binary Search, Sorting | ![][easy] | |
203207
| **0350** | [Intersection of Two Arrays II][350] | Array, Hash Table, Two Pointers, Binary Search, Sorting | ![][easy] | |
204208
| **0389** | [Find the Difference][389] | Hash Table, String, Bit Manipulation, Sorting | ![][easy] | |
209+
| **0414** | [Third Maximum Number][414] | Array, Sorting | ![][easy] | |
205210
| **0502** | [IPO][502] | Array, Greedy, Sorting, Heap (Priority Queue) | ![][hard] | |
206211
| **0506** | [Relative Ranks][506] | Array, Sorting, Heap | ![][easy] | |
207212
| **0888** | [Fair Candy Swap][888] | Array, Hash Table, Binary Search, Sorting | ![][easy] | |
@@ -402,6 +407,7 @@
402407
| **0338** | [Counting Bits][338] | Dynamic Programming, Bit Manip | ![][easy] | |
403408
| **0342** | [Power of Four][342] | Math, Bit Manipulation, Recursion | ![][easy] | |
404409
| **0389** | [Find the Difference][389] | Hash Table, String, Bit Manipulation, Sorting | ![][easy] | |
410+
| **0401** | [Binary Watch][401] | Backtracking, Bit Manip | ![][easy] | |
405411
| **1461** | [Check If a String Contains All Binary Codes of Size K][1461] | String, Hash Table, Bit Manipulation | ![][medium] | |
406412

407413
<!---------------------------------{ Solution Table }-------------------------->
@@ -454,6 +460,7 @@
454460
| :------: | :---------------: | :----------------------------------------: | :--------: | :----: |
455461
| **0067** | [Add Binary][67] | Math, String, Bit Manipulation, Simulation | ![][easy] | |
456462
| **0258** | [Add Digits][258] | Math, Simulation, Number Theory | ![][easy] | |
463+
| **0412** | [Fizz Buzz][412] | Math, String, Simulation | ![][easy] | |
457464

458465
<!---------------------------------{ Solution Table }-------------------------->
459466

@@ -466,6 +473,7 @@
466473
| **0051** | [N-Queens][51] | Array, Backtracking | ![][hard] | |
467474
| **0078** | [Subsets][78] | Array, Backtracking, Bit Manip | ![][medium] | |
468475
| **0257** | [Binary Tree Paths][257] | String, Backtracking, Tree, Depth-First Search, Binary Tree | ![][easy] | |
476+
| **0401** | [Binary Watch][401] | Backtracking, Bit Manip | ![][easy] | |
469477

470478
<!---------------------------------{ Solution Table }-------------------------->
471479

@@ -974,7 +982,10 @@
974982
[387]: ./solution/0301-0400/387%20-%20First%20Unique%20Character%20in%20a%20String.md
975983
[389]: ./solution/0301-0400/389%20-%20Find%20the%20Difference.md
976984
[392]: ./solution/0301-0400/392%20-%20Is%20Subsequence.md
985+
[401]: ./solution/0401-0500/401%20-%20Binary%20Watch.md
977986
[404]: ./solution/0401-0500/404%20-%20Sum%20of%20Left%20Leaves.md
987+
[412]: ./solution/0401-0500/412%20-%20Fizz%20Buzz.md
988+
[414]: ./solution/0401-0500/414%20-%20Third%20Maximum%20Number.md
978989
[438]: ./solution/0401-0500/438%20-%20Find%20All%20Anagrams%20in%20a%20String.md
979990
[442]: ./solution/0401-0500/442%20-%20Find%20All%20Duplicates%20in%20an%20Array.md
980991
[445]: ./solution/0401-0500/445%20-%20Add%20Two%20Numbers%20II.md
@@ -1010,6 +1021,7 @@
10101021
[1580]: ./solution/1401-1500/1470%20-%20Shuffle%20the%20Array.md
10111022
[1630]: ./solution/1501-1600/1523.%20Count%20Odd%20Numbers%20in%20an%20Interval%20Range.md
10121023
[1957]: ./solution/1901-2000/1957%20-%20Delete%20Characters%20to%20Make%20Fancy%20String.md
1024+
[2176]: ./solution/2101-2200/2176%20-%20Count%20Equal%20and%20Divisible%20Pairs%20in%20an%20Array.md
10131025
[2236]: ./solution/2201-2300/2236%20-%20Root%20Equals%20Sum%20of%20Children.md
10141026

10151027
<!----------------------------------{ Labels }--------------------------------->
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# 401. Binary Watch [![share]](https://leetcode.com/problems/binary-watch/)
2+
3+
![][easy]
4+
5+
## Problem Statement
6+
7+
<p>A binary watch has 4 LEDs on the top to represent the hours (0-11), and 6 LEDs on the bottom to represent the minutes (0-59). Each LED represents a zero or one, with the least significant bit on the right.</p>
8+
<ul>
9+
<li>For example, the below binary watch reads <code>"4:51"</code>.</li>
10+
</ul>
11+
<p><img alt="" src="https://assets.leetcode.com/uploads/2021/04/08/binarywatch.jpg" style="width: 500px; height: 500px;"/></p>
12+
<p>Given an integer <code>turnedOn</code> which represents the number of LEDs that are currently on (ignoring the PM), return <em>all possible times the watch could represent</em>. You may return the answer in <strong>any order</strong>.</p>
13+
<p>The hour must not contain a leading zero.</p>
14+
<ul>
15+
<li>For example, <code>"01:00"</code> is not valid. It should be <code>"1:00"</code>.</li>
16+
</ul>
17+
<p>The minute must be consist of two digits and may contain a leading zero.</p>
18+
<ul>
19+
<li>For example, <code>"10:2"</code> is not valid. It should be <code>"10:02"</code>.</li>
20+
</ul>
21+
<p> </p>
22+
<p><strong class="example">Example 1:</strong></p>
23+
24+
```
25+
Input: turnedOn = 1
26+
Output: ["0:01","0:02","0:04","0:08","0:16","0:32","1:00","2:00","4:00","8:00"]
27+
```
28+
29+
<p><strong class="example">Example 2:</strong></p>
30+
31+
```
32+
Input: turnedOn = 9
33+
Output: []
34+
```
35+
36+
<p> </p>
37+
<p><strong>Constraints:</strong></p>
38+
<ul>
39+
<li><code>0 &lt;= turnedOn &lt;= 10</code></li>
40+
</ul>
41+
42+
::: details _Click to open Hints_
43+
44+
- Simplify by seeking for solutions that involve comparing bit counts.
45+
- Consider calculating all possible times for comparison purposes.
46+
47+
:::
48+
49+
## Solution:
50+
51+
::: code-group
52+
53+
```rs [Rust]
54+
impl Solution {
55+
pub fn read_binary_watch(turned_on: i32) -> Vec<String> {
56+
let mut res = Vec::new();
57+
58+
// 12 hours, 60 minutes
59+
// here we use 0_i32 to avoid the warning of type inference
60+
for i in 0_i32..12 {
61+
for j in 0_i32..60 {
62+
// if the sum of the number of 1s in the binary representation
63+
// of the hour and minute is equal to turned_on,
64+
// then the time is added to the res
65+
if i.count_ones() + j.count_ones() == turned_on as u32 {
66+
res.push(format!("{}:{:02}", i, j));
67+
}
68+
}
69+
}
70+
71+
res
72+
}
73+
}
74+
75+
```
76+
77+
:::
78+
79+
### [_..._](#)
80+
81+
```
82+
83+
```
84+
85+
<!----------------------------------{ link }--------------------------------->
86+
87+
[share]: https://graph.org/file/3ea5234dda646b71c574a.png
88+
[easy]: https://img.shields.io/badge/Difficulty-Easy-bright.svg
89+
[medium]: https://img.shields.io/badge/Difficulty-Medium-yellow.svg
90+
[hard]: https://img.shields.io/badge/Difficulty-Hard-red.svg
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# 412. Fizz Buzz [![share]](https://leetcode.com/problems/fizz-buzz/)
2+
3+
![][easy]
4+
5+
## Problem Statement
6+
7+
<p>Given an integer <code>n</code>, return <em>a string array </em><code>answer</code><em> (<strong>1-indexed</strong>) where</em>:</p>
8+
<ul>
9+
<li><code>answer[i] == "FizzBuzz"</code> if <code>i</code> is divisible by <code>3</code> and <code>5</code>.</li>
10+
<li><code>answer[i] == "Fizz"</code> if <code>i</code> is divisible by <code>3</code>.</li>
11+
<li><code>answer[i] == "Buzz"</code> if <code>i</code> is divisible by <code>5</code>.</li>
12+
<li><code>answer[i] == i</code> (as a string) if none of the above conditions are true.</li>
13+
</ul>
14+
<p> </p>
15+
<p><strong class="example">Example 1:</strong></p>
16+
17+
```
18+
Input: n = 3
19+
Output: ["1","2","Fizz"]
20+
```
21+
22+
<p><strong class="example">Example 2:</strong></p>
23+
24+
```
25+
Input: n = 5
26+
Output: ["1","2","Fizz","4","Buzz"]
27+
```
28+
29+
<p><strong class="example">Example 3:</strong></p>
30+
31+
```
32+
Input: n = 15
33+
Output: ["1","2","Fizz","4","Buzz","Fizz","7","8","Fizz","Buzz","11","Fizz","13","14","FizzBuzz"]
34+
```
35+
36+
<p> </p>
37+
<p><strong>Constraints:</strong></p>
38+
<ul>
39+
<li><code>1 &lt;= n &lt;= 10<sup>4</sup></code></li>
40+
</ul>
41+
42+
## Solution:
43+
44+
::: code-group
45+
46+
```rs [Rust]
47+
impl Solution {
48+
pub fn fizz_buzz(n: i32) -> Vec<String> {
49+
let mut res = Vec::new();
50+
51+
for i in 1..=n {
52+
// same as divisible by 3 and 5
53+
if i % 15 == 0 {
54+
res.push("FizzBuzz".to_string());
55+
} else if i % 3 == 0 {
56+
res.push("Fizz".to_string());
57+
} else if i % 5 == 0 {
58+
res.push("Buzz".to_string());
59+
} else {
60+
res.push(i.to_string());
61+
}
62+
}
63+
64+
res
65+
}
66+
}
67+
68+
```
69+
70+
:::
71+
72+
### [_..._](#)
73+
74+
```
75+
76+
```
77+
78+
<!----------------------------------{ link }--------------------------------->
79+
80+
[share]: https://graph.org/file/3ea5234dda646b71c574a.png
81+
[easy]: https://img.shields.io/badge/Difficulty-Easy-bright.svg
82+
[medium]: https://img.shields.io/badge/Difficulty-Medium-yellow.svg
83+
[hard]: https://img.shields.io/badge/Difficulty-Hard-red.svg

0 commit comments

Comments
(0)

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