10000 I added new solution implemented in java · haoel/leetcode@7448c2e · GitHub
[go: up one dir, main page]

Skip to content

Commit 7448c2e

Browse files
committed
I added new solution implemented in java
1 parent c965a16 commit 7448c2e

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Source : https://leetcode.com/problems/plus-one/description/
2+
// Author : Anas Mak
3+
// Date : 2023-01-26
4+
5+
/**********************************************************************************
6+
* You are given a large integer represented as an integer array digits,
7+
* where each digits[i] is the ith digit of the integer.
8+
* The digits are ordered from most significant to least significant in left-to-right order.
9+
* The large integer does not contain any leading 0's.
10+
* Increment the large integer by one and return the resulting array of digits.
11+
**********************************************************************************/
12+
13+
package Solution;
14+
15+
class Solution {
16+
public int[] plusOne(int[] digits) {
17+
for(int i = digits.length - 1 ; i >=0 ; i--){
18+
if(digits[i] != 9){
19+
digits[i]+=1;
20+
return digits;
21+
}
22+
23+
else{
24+
digits[i] = 0;
25+
}
26+
}
27+
28+
int[] array = new int[digits.length + 1];
29+
array[0] = 1;
30+
return array;
31+
}
32+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package Solution;
2+
3+
import org.junit.Assert;
4+
import org.junit.Test;
5+
6+
/**
7+
* Test for 66. Plus One
8+
*/
9+
public class PlusOne {
10+
@Test
11+
public void test() {
12+
Solution solution = new Solution();
13+
int[] array1 = [4,3,2,1];
14+
Assert.assertTrue(solution.PlusOne(array1) == [4,3,2,2]);
15+
int[] array2 = [1,2,3];
16+
Assert.assertTrue(solution.SingleNumber(array2) == [1,2,4]);
17+
int[] array3 = [9];
18+
Assert.assertTrue(solution.SingleNumber(array3) == [1,0]);
19+
20+
}
21+
}

algorithms/java/src/SingleNumber/SingleNumberTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
import org.junit.Test;
55

66
/**
7-
* Test for 58. Length of Last Word
7+
* Test for 136. Single Number
88
*/
9-
public class TestLengthOfLastWord {
9+
public class SingleNumber {
1010
@Test
1111
public void test() {
1212
Solution solution = new Solution();

0 commit comments

Comments
 (0)
0