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 ...
随机推荐
- java的static块执行时机<转>
一.误区:简单认为JAVA静态代码块在类被加载时就会自动执行.证错如下: class MyClass1 { static {//静态块 System.out.println("static ...
- git关联远程仓库命令<原>
一.存在远程仓库了,本地想克隆其代码: $ git clone git@git.oschina.net:winkey4986/Weather_demo.git 二.本地有代码了,想在建个远程仓库保存代 ...
- ionic2 生命周期
在 Ionic 2 的版本中生命周期命名的改变,以及各个事件的解释. 官方文档地址在 这里 . 事件名称 事件说明 ionViewLoaded 页面加载完毕触发.该事件发生在页面被创建成 DOM 的时 ...
- esayUI实践的一些体会
1.如何在页面中使用 easy ui ? 引入 四个文件 <!-- 引入easy ui --> <link rel="stylesheet" type=" ...
- Droptiles - 炫酷的 Metro 风格的层叠式 Web 面板
介绍 Droptiles是一套Metro风格的类似Win8的Web2.0控制面板.它采用图块(tiles)建立用户体验.图块(tiles)是一些可以从外部资源中获取数据的迷你应用.点击图块(tile) ...
- [Eclipse] 项目编码
一.修改eclipse的新建项目的编码 在菜单栏的 Window->Preferences->General->Workspace->Text file encoding 将其 ...
- 转:Python操作SQLServer示例
注:此文也是转载,2018年1月发现此文阅读量过万,略感不安.当时只是为了自己存档学习,未粘此文的原始连接.如有侵权,通过即删除,敬请谅解! 从网上找的,估计原文是:Python操作SQLServer ...
- CentOS 6.5在grub界面下更改root密码
想要更改CentOS 7 root的密码或者忘记了root的密码的时候可以在grub界面下更改root的密码. 百度了很多内容,更多方法都是适用于centos6及以前版本的,终于找到一个可以的. 1. ...
- Linux的缓存内存 Cache Memory详解
http://www.ha97.com/4337.html PS:前天有童鞋问我,为啥我的Linux系统没运行多少程序,显示的可用内存这么少?其实Linux与Win的内存管理不同,会尽量缓存内存以提高 ...
- Http Digest认证协议
转自:http://blog.csdn.net/htjoy1202/article/details/7067287 其认证的基本框架为挑战认证的结构,如下图所示: 1.客户端希望取到服务器上的某个资源 ...