본문으로 바로가기

[LeetCode/릿코드] 66. Plus One

category [JAVA] LeetCode/Easy 2023. 1. 24. 18:49
728x90
반응형

문제

 

 

반응형

풀이

 

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import java.math.BigInteger;
import java.util.Arrays;
class Solution {
    public int[] plusOne(int[] digits) {
      String num = "";
        for(int i=0; i<digits.length; i++) {
            num += digits[i];
        }
        BigInteger big = new BigInteger(num);
        BigInteger plus = big.add(BigInteger.ONE);
        
        String str = plus.toString();
        String[] strArr = str.split("");
        
        int[] answer = Arrays.stream(strArr)
                .mapToInt(Integer::parseInt)
                .toArray();
        return answer;
    }
}
cs

 

728x90
반응형