Skip to content

Commit b0cd196

Browse files
committed
✨feat: Add 412
1 parent 08452f5 commit b0cd196

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

Index/模拟.md

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
| [284. 顶端迭代器](https://leetcode-cn.com/problems/peeking-iterator/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/peeking-iterator/solution/gong-shui-san-xie-die-dai-qi-ji-ben-ren-b77lz/) | 中等 | 🤩🤩🤩🤩 |
2929
| [345. 反转字符串中的元音字母](https://leetcode-cn.com/problems/reverse-vowels-of-a-string/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/reverse-vowels-of-a-string/solution/gong-shui-san-xie-note-bie-pian-shuang-z-c8ii/) | 简单 | 🤩🤩🤩 |
3030
| [405. 数字转换为十六进制数](https://leetcode-cn.com/problems/convert-a-number-to-hexadecimal/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/convert-a-number-to-hexadecimal/solution/gong-shui-san-xie-yi-ti-shuang-jie-jin-z-d93o/) | 简单 | 🤩🤩🤩🤩 |
31+
| [412. Fizz Buzz](https://leetcode-cn.com/problems/fizz-buzz/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/fizz-buzz/solution/gong-shui-san-xie-jian-dan-mo-ni-ti-by-a-jll0/) | 简单 | 🤩🤩🤩🤩 |
3132
| [413. 等差数列划分](https://leetcode-cn.com/problems/arithmetic-slices/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/arithmetic-slices/solution/gong-shui-san-xie-shuang-zhi-zhen-qiu-ji-ef1q/) | 中等 | 🤩🤩🤩🤩 |
3233
| [414. 第三大的数](https://leetcode-cn.com/problems/third-maximum-number/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/third-maximum-number/solution/gong-shui-san-xie-yi-ti-shuang-jie-pai-x-pmln/) | 中等 | 🤩🤩🤩🤩 |
3334
| [434. 字符串中的单词数](https://leetcode-cn.com/problems/number-of-segments-in-a-string/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/number-of-segments-in-a-string/solution/gong-shui-san-xie-jian-dan-zi-fu-mo-ni-t-0gx6/) | 简单 | 🤩🤩🤩🤩 |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
### 题目描述
2+
3+
这是 LeetCode 上的 **[412. Fizz Buzz](https://leetcode-cn.com/problems/fizz-buzz/solution/gong-shui-san-xie-jian-dan-mo-ni-ti-by-a-jll0/)** ,难度为 **简单**
4+
5+
Tag : 「模拟」
6+
7+
写一个程序,输出从 `1``n` 数字的字符串表示。
8+
9+
1. 如果 `n` 是 `3` 的倍数,输出 `“Fizz”`
10+
11+
2. 如果 `n` 是 `5` 的倍数,输出 `“Buzz”`
12+
13+
3. 如果 `n` 同时是 `3``5` 的倍数,输出 `“FizzBuzz”`
14+
15+
示例:
16+
```
17+
n = 15,
18+
19+
返回:
20+
[
21+
"1",
22+
"2",
23+
"Fizz",
24+
"4",
25+
"Buzz",
26+
"Fizz",
27+
"7",
28+
"8",
29+
"Fizz",
30+
"Buzz",
31+
"11",
32+
"Fizz",
33+
"13",
34+
"14",
35+
"FizzBuzz"
36+
]
37+
```
38+
39+
---
40+
41+
### 模拟
42+
43+
根据题意进行模拟。
44+
45+
代码:
46+
```Java []
47+
class Solution {
48+
public List<String> fizzBuzz(int n) {
49+
List<String> ans = new ArrayList<>();
50+
for (int i = 1; i <= n; i++) {
51+
String cur = "";
52+
if (i % 3 == 0) cur += "Fizz";
53+
if (i % 5 == 0) cur += "Buzz";
54+
if (cur.length() == 0) cur = i + "";
55+
ans.add(cur);
56+
}
57+
return ans;
58+
}
59+
}
60+
```
61+
* 时间复杂度:$O(n)$
62+
* 空间复杂度:$O(n)$
63+
64+
---
65+
66+
### 最后
67+
68+
这是我们「刷穿 LeetCode」系列文章的第 `No.412` 篇,系列开始于 2021/01/01,截止于起始日 LeetCode 上共有 1916 道题目,部分是有锁题,我们将先把所有不带锁的题目刷完。
69+
70+
在这个系列文章里面,除了讲解解题思路以外,还会尽可能给出最为简洁的代码。如果涉及通解还会相应的代码模板。
71+
72+
为了方便各位同学能够电脑上进行调试和提交代码,我建立了相关的仓库:https://github.com/SharingSource/LogicStack-LeetCode
73+
74+
在仓库地址里,你可以看到系列文章的题解链接、系列文章的相应代码、LeetCode 原题链接和其他优选题解。
75+

0 commit comments

Comments
 (0)