Skip to content

Commit f3a6d7f

Browse files
committed
07/29 fizzbuzz
1 parent 7f951f8 commit f3a6d7f

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ Feel free to submit pull requests, add issues and be a contributer.
9999
| Leetcode | [387. First Unique Character in a String](https://leetcode.com/problems/first-unique-character-in-a-string/) | [Java](./java/FirstUniqChar.java) | _O(n)_ | _O(n)_ | Easy | |
100100
| Leetcode | [389. Find the Difference](https://leetcode.com/problems/find-the-difference/description/) | [Java](./java/findTheDifference.java) | _O(n)_ | _O(1)_ | Easy | |
101101
| Leetcode | [408. Valid Word Abbreviation](https://leetcode.com/problems/valid-word-abbreviation/description/) | [Java](./java/validWordAbbreviation.java) | _O(n)_ | _O(1)_ | Easy | |
102+
| Leetcode | [412. Fizz Buzz](https://leetcode.com/problems/fizz-buzz/discuss/89941/Java-easy-iterative-solution) | [Java](./java/fizzbuzz.java) | _O(n)_ | _O(1)_ | Easy | |
102103
| Leetcode | [422. Valid Word Square](https://leetcode.com/problems/valid-word-square/description/) | [Java](./java/validWordSquare.java) | _O(n)_ | _O(1)_ | Easy | |
103104
| Leetcode | [479. Largest Palindrome Product](https://leetcode.com/problems/largest-palindrome-product/description/) | [Java](./java/largestPalindrome.java) | _O(n)_ | _O(1)_ | Medium | |
104105
| Leetcode | [482. License Key Formatting](https://leetcode.com/problems/license-key-formatting/description/) | [Java](./java/licenseKeyFormatting.java) | _O(n)_ | _O(1)_ | Medium | |

java/fizzbuzz.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public List<String> fizzBuzz(int n) {
3+
List<String> result = new ArrayList<>();
4+
5+
for(int i=1; i<=n; i++){
6+
if(i%3==0 && i%5==0)
7+
result.add("FizzBuzz");
8+
else if(i%3 == 0)
9+
result.add("Fizz");
10+
else if(i%5 == 0)
11+
result.add("Buzz");
12+
else
13+
result.add(String.valueOf(i));
14+
}
15+
16+
return result;
17+
}
18+
}

0 commit comments

Comments
 (0)