66. Plus One

原创 2016年06月01日 18:41:01

Given a non-negative number represented as an array of digits, plus one to the number.

The digits are stored such that the most significant digit is at the head of the list.

import java.math.BigInteger;

public class Solution {
    public int[] plusOne(int[] digits) {
        
      		String str = "";
		
		String[] strs = new String[digits.length];
		
		for(int i=0;i<digits.length;i++){
			
			strs[i] = String.valueOf(digits[i]);
			
		}
		
		for(int i=0;i<digits.length;i++){
			
			str = str + strs[i];
			
		}
		
		BigInteger bigNumber = new BigInteger("1");
		
		BigInteger bigNumber2 = new BigInteger(str);
		
		BigInteger bigNumber3 = bigNumber.add(bigNumber2);
		
		//System.out.println(str.length());
		
		//int number2 = number + 1;
		
		String str2 = String.valueOf(bigNumber3);
		
		int[] digits2 = new int[str2.length()];
		
		for(int i=0;i<str2.length();i++){
			
			digits2[i] = Integer.parseInt(str2.substring(i, i+1));
			
		}
		
		return digits2;
	}
        
        
        
    }


版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

LeetCode --- 66. Plus One

题目链接:Plus One Given a non-negative number represented as an array of digits, plus one to the number...
  • makuiyu
  • makuiyu
  • 2015年03月19日 21:53
  • 6303

leetcode 66. Plus One

leetcode 66. Plus One 题目大意:给定一个非负整数,存储在数组中,把这个数字加1,这个数的最高位在最前面。 解题思路:如果这个数的最低位为小于9,直接加到最低位去 如果这个数的最低...

leetcode-66. Plus One

Given a non-negative number represented as an array of digits, plus one to the number. The digits...
  • qj30212
  • qj30212
  • 2016年09月02日 00:34
  • 146

[C语言][LeetCode][66]Plus One

题目Plus One Given a non-negative number represented as an array of digits, plus one to the number. ...
  • Timsley
  • Timsley
  • 2015年08月11日 08:58
  • 1048

66. Plus One某数+1(通过放到数组里)--Array

66. Plus One某数+1(通过放到数组里)--Array Given a non-negative number represented as an array of digits, plu...

leetcode 21_Merge Two Sorted Lists & leetcode_258 Add Digits & leetcode_66plus one

l leetcode 21_Merge Two Sorted Lists 题目:Merge two sorted linked lists and return it as a new list...

66. Plus One(Java) & 43. Multiply Strings

题目:Given a non-negative number represented as an array of digits, plus one to the number. The digit...

66. Plus One

Given a non-negative integer represented as a non-empty array of digits, plus one to the integer.You...

<LeetCode OJ> 66. Plus One

66. Plus One My Submissions Question Total Accepted: 77253 Total Submissions: 242942 Difficulty:...

27. Remove Element \ 66. Plus One \ 88. Merge Sorted Array

27. Remove Element法一:class Solution { public: int removeElement(vector& nums, int val) { ...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:66. Plus One
举报原因:
原因补充:

(最多只允许输入30个字)