File tree Expand file tree Collapse file tree 5 files changed +78
-0
lines changed Expand file tree Collapse file tree 5 files changed +78
-0
lines changed Original file line number Diff line number Diff line change 1+ // https://leetcode.com/problems/broken-calculator/
2+
3+ public int brokenCalc (int startValue , int target ) {
4+
5+
6+ if (startValue >= target ){
7+ return startValue - target ;
8+ }
9+
10+ if (target % 2 == 0 ){
11+ return 1 +brokenCalc (startValue ,target /2 );
12+ }
13+
14+ return 1 +brokenCalc (startValue ,target +1 );
15+
16+ }
Original file line number Diff line number Diff line change 1+
2+ import java .util .ArrayList ;
3+ import java .util .List ;
4+
5+ // https://leetcode.com/problems/fizz-buzz/
6+
7+
8+ public List <String > fizzBuzz (int n ) {
9+ List <String > s = new ArrayList <>();
10+
11+ for (int i = 1 ; i <= n ; i ++) {
12+ if ( i % 15 == 0 ){
13+ s .add ("FizzBuzz" );
14+ }else if ( i % 3 == 0 ){
15+ s .add ("Fizz" );
16+ }else if (i % 5 == 0 ){
17+ s .add ("Buzz" );
18+ }else {
19+ s .add (Integer .toString (i ));
20+ }
21+ }
22+ return s ;
23+ }
Original file line number Diff line number Diff line change 1+
2+
3+ // https://leetcode.com/problems/sign-of-the-product-of-an-array/
4+
5+ public int arraySign (int [] nums ) {
6+ int count = 0 ;
7+ for (int i : nums ){
8+ if (i == 0 ){
9+ return 0 ;
10+ }else if (i < 0 ){
11+ count ++;
12+ }
13+ }
14+ if (count % 2 == 0 ){
15+ return 1 ;
16+ }
17+ return -1 ;
18+ }
Original file line number Diff line number Diff line change 1+
2+
3+ // https://leetcode.com/problems/water-bottles/
4+
5+
6+ public int numWaterBottles (int numBottles , int numExchange ) {
7+
8+ int total = numBottles ;
9+ while (numBottles >=numExchange )
10+ {
11+ int exchange =numBottles /numExchange ;
12+ int rem =numBottles %numExchange ;
13+ total +=exchange ;
14+ numBottles =exchange +rem ;
15+ }
16+ return total ;
17+ }
Original file line number Diff line number Diff line change @@ -314,6 +314,10 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu
314314| 13 | [ Roman to Integer] ( https://leetcode.com/problems/roman-to-integer ) | [ Java] ( ./Java/roman-to-integer.java ) <br > [ C++] ( ./C++/Roman_to_Integer.cpp ) | _ O(n)_ | _ O(1)_ | Easy | Math | |
315315| 14 | [ Arithmetic Subarrays] ( https://leetcode.com/problems/arithmetic-subarrays/ ) | [ Java] ( ./Java/Arithmetic-Subarrays.java ) | _ O(m\* n)_ | _ O(n)_ | Medium | Math | Pattern Count |
316316| 263 | [ Ugly Number] ( https://leetcode.com/problems/ugly-number/ ) | [ Java] ( ./Java/Ugly-Number.java ) | _ O(n)_ | _ O(n)_ | Easy | Math | |
317+ | 412 | [ Fizz Buzz] ( https://leetcode.com/problems/fizz-buzz/ ) | [ Java] ( ./Java/FizzBuzz.java ) | _ O(n)_ | _ O(n)_ | Easy | Math | |
318+ | 1518 | [ Water Bottles] ( https://leetcode.com/problems/water-bottles/ ) | [ Java] ( ./Java/WaterBottles.java ) | _ O(n)_ | _ O(n)_ | Easy | Math | |
319+ | 1822 | [ Sign Of Product] ( https://leetcode.com/problems/sign-of-the-product-of-an-array/ ) | [ Java] ( ./Java/SignOf.java ) | _ O(n)_ | _ O(n)_ | Easy | Math | |
320+ | 991 | [ Broken Calculator] ( https://leetcode.com/problems/broken-calculator/ ) | [ Java] ( ./Java/BrokenCalculator.java ) | _ O(n)_ | _ O(n)_ | Medium | Math | |
317321
318322<br />
319323<div align =" right " >
You can’t perform that action at this time.
0 commit comments