LeetCode - PlusOne
题意:给一个数按位存放在一个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的更多相关文章
- leetcode — plus-one
import java.util.ArrayList; import java.util.Arrays; import java.util.List; /** * Source : https://o ...
- [LeetCode 题解]: plusOne
前言 [LeetCode 题解]系列传送门: http://www.cnblogs.com/double-win/category/573499.html 1.题目描述 Given a no ...
- [LeetCode] Plus One Linked List 链表加一运算
Given a non-negative number represented as a singly linked list of digits, plus one to the number. T ...
- [LeetCode] Plus One 加一运算
Given a non-negative number represented as an array of digits, plus one to the number. The digits ar ...
- Leetcode分类刷题答案&心得
Array 448.找出数组中所有消失的数 要求:整型数组取值为 1 ≤ a[i] ≤ n,n是数组大小,一些元素重复出现,找出[1,n]中没出现的数,实现时时间复杂度为O(n),并不占额外空间 思路 ...
- leetcode算法分类
利用堆栈:http://oj.leetcode.com/problems/evaluate-reverse-polish-notation/http://oj.leetcode.com/problem ...
- LeetCode Plus One Linked List
原题链接在这里:https://leetcode.com/problems/plus-one-linked-list/ 题目: Given a non-negative number represen ...
- leetcode bugfree note
463. Island Perimeterhttps://leetcode.com/problems/island-perimeter/就是逐一遍历所有的cell,用分离的cell总的的边数减去重叠的 ...
- LeetCode题目分类
利用堆栈:http://oj.leetcode.com/problems/evaluate-reverse-polish-notation/http://oj.leetcode.com/problem ...
随机推荐
- DVI与DVI-D的区别
DVI-I兼容DVI-D和VGA,如果不使用VGA信号兼容,那么没有任何区别. 1) DVI接口是1999年由数字显示工作组DDWG(Digital Display Working Group)推出的 ...
- MySQL LIMIT 如何改写成Oracle limit
mysql代码 SELECT * FROM tablename LIMIT 100,15 首先,Oracle是不支持limit的.个人感觉分页方面mysql比Oracle要好些.处理代码如下: sel ...
- 利用JavaScript计算引擎进行字符串公式运算
1.通过js计算引擎计算(java自带) 2.计算公式除了支持基本的方法之外还支持简单js脚本分支计算 3.通过设定map传入参数 4.默认返回最后一个计算结果,如果需返回特定值,将变量补写在公式最后 ...
- 【C】——指针与const限定符
const限定符和指针结合起来常见的情况有以下几种. const int *a; int const *a; 这两种写法是一样的,a是一个指向const int型的指针,a所指向的内存单元不可改写,所 ...
- MODEL-View-Controller,既模型-视图-控制器
Swing组件采用MVC(MODEL-View-Controller,既模型-视图-控制器)设计模式,其中模型(Model)用于维护组件的各种状态,视图(View)是组件的可视化表现,控制器(Cont ...
- ti8127下godb 开发
http://download.cnet.com/GoDB/3000-2212_4-10306159.html源码rdk https://github.com/vasa-c/go-db github ...
- Sublime Text3打造U盘便携Lua IDE
下载Sublime Text 链接http://www.sublimetext.com/3 我下载的是win32 portable 版 便于放入U盘携带 解压 注冊: 能够复制下面部分直接贴入注冊栏 ...
- c++ 静态成员变量
在C++中,静态成员是属于整个类的而不是某个对象,静态成员变量只存储一份供所有对象共用.所以在所有对象中都可以共享它.使用静态成员变量实现多个对象之间的数据共享不会破坏隐藏的原则,保证了安全性还可以节 ...
- poj 3740 Easy Finding(Dancing Links)
Easy Finding Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 15668 Accepted: 4163 Des ...
- GC浅析之三-性能调优经验总结
性能调优经验总结 问题的出现: 在日常环境下,以某server 为例,该机器的每秒的访问量均值在368左右,最大访问量在913.对外提供服务的表现为每两三个小时就有秒级别的时间客户端请求超时,在访问量 ...