题解 | #加一#

加一

http://www.nowcoder.com/practice/4d135ddb2e8649ddb59ee7ac079aa882

傻瓜式写法 import java.util.*; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; import java.math.BigInteger; public class Solution { /** * * @param digits int整型一维数组 * @return int整型一维数组 */ public int[] plusOne (int[] digits) { // write code here List list = Arrays.stream(digits).boxed().collect(Collectors.toList()); StringBuilder stringBuilder=new StringBuilder(); for (int i = 0; i <list.size() ; i++) { stringBuilder.append(list.get(i)); } BigInteger a=new BigInteger(stringBuilder.toString()); BigInteger b=a.add(BigInteger.valueOf(1)); StringBuilder builder=new StringBuilder(); builder.append(b); int[] arr = new int[builder.length()]; for (int i = 0; i <builder.length() ; i++) { arr[i] = Integer.parseInt(String.valueOf(builder.charAt(i))); } return arr ; } }

全部评论

相关推荐

点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务