题意:给一个数按位存放在一个int数组中,要求返回这个数加一后的数组。

懒人解法:

public class Solution {
public int[] plusOne(int[] digits) {
java.math.BigInteger Bigdigits = new java.math.BigInteger(toString(digits));
String s = Bigdigits.add(new java.math.BigInteger("1")).toString();
return toArray(s);
}
public static String toString(int[] d) {
StringBuilder sb = new StringBuilder();
for(int i=0; i<d.length; i++) {
sb.append(d[i]);
}
return sb.toString();
}
public static int[] toArray(String s) {
int[] ans = new int[s.length()];
for(int i=0; i<s.length(); i++) {
ans[i] = s.charAt(i) - '0';
}
return ans;
}
}

LeetCode - PlusOne的更多相关文章

  1. leetcode — plus-one

    import java.util.ArrayList; import java.util.Arrays; import java.util.List; /** * Source : https://o ...

  2. [LeetCode 题解]: plusOne

    前言   [LeetCode 题解]系列传送门:  http://www.cnblogs.com/double-win/category/573499.html   1.题目描述 Given a no ...

  3. [LeetCode] Plus One Linked List 链表加一运算

    Given a non-negative number represented as a singly linked list of digits, plus one to the number. T ...

  4. [LeetCode] Plus One 加一运算

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

  5. Leetcode分类刷题答案&心得

    Array 448.找出数组中所有消失的数 要求:整型数组取值为 1 ≤ a[i] ≤ n,n是数组大小,一些元素重复出现,找出[1,n]中没出现的数,实现时时间复杂度为O(n),并不占额外空间 思路 ...

  6. leetcode算法分类

    利用堆栈:http://oj.leetcode.com/problems/evaluate-reverse-polish-notation/http://oj.leetcode.com/problem ...

  7. LeetCode Plus One Linked List

    原题链接在这里:https://leetcode.com/problems/plus-one-linked-list/ 题目: Given a non-negative number represen ...

  8. leetcode bugfree note

    463. Island Perimeterhttps://leetcode.com/problems/island-perimeter/就是逐一遍历所有的cell,用分离的cell总的的边数减去重叠的 ...

  9. LeetCode题目分类

    利用堆栈:http://oj.leetcode.com/problems/evaluate-reverse-polish-notation/http://oj.leetcode.com/problem ...

随机推荐

  1. 线程安全的atomic wrapper classes例子

    先参考一个例子 http://www.cnblogs.com/aigongsi/archive/2012/04/01/2429166.html#!comments 即使只是i++,实际上也是由多个原子 ...

  2. Android AsyncTask 源代码分析

    AsyncTask源代码分析 public abstract class AsyncTask<Params, Progress, Result> { //日志TAG private sta ...

  3. Android——通知 Notification

    链接:http://jingyan.baidu.com/article/77b8dc7fde875a6175eab641.html http://www.2cto.com/kf/201502/3749 ...

  4. JSON对应的maven依赖包

    常用有三种json解析jackson.fastjson.gson. jackson依赖包 <!-- https://mvnrepository.com/artifact/com.fasterxm ...

  5. hadoop中的Jobhistory历史服务器

    1.  启动脚本 mr-jobhistory-daemon.sh start historyserver 2. 配置说明 jobhistory用于查询每个job运行完以后的历史日志信息,是作为一台单独 ...

  6. EMS快递单号生成算法

    <?php function emsnum($ems, $num) { $fri = substr($ems, 2, 8); $head = substr($ems, 0, 2); $tail ...

  7. 21个最佳jQuery插件推荐

    在Javascript应用领域上,使用jQuery可以制作出非常优秀的动画效果,滑块.滑球,以及各种不同的应用.精选出21个最佳的精典案例,如果你是一个前端设计师,一定不要错过. Supersized ...

  8. opencv3.2 dnn 图像分割

    下载 http://dl.caffe.berkeleyvision.org/fcn32s-heavy-pascal.caffemodel 在opencv_contrib-3.2.0/modules/d ...

  9. Spring 4 官方文档学习(十一)Web MVC 框架之URI Builder

    http://docs.spring.io/spring/docs/current/spring-framework-reference/html/mvc.html#mvc-uri-building ...

  10. e578. Setting the Clipping Area with a Shape

    This example demonstrates how to set a clipping area using a shape. The example sets an oval for the ...