1. Plus One My Submissions QuestionEditorial Solution

    Total Accepted: 98403 Total Submissions: 292594 Difficulty: Easy

    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.

思路:

比较简单,有进位,当前为置为0,判断下一位+1是否为10,如此继续

最后看最高位是否进位,有进位,插入新的1

时间复杂度:O(n)

空间:O(1)

class Solution {
public:
vector<int> plusOne(vector<int>& digits) {//这里没说是否修改digits,也没定义为const,所以可以不用另外用存储空间
int n=digits.size();
int k=n-1;
while(k>=0&&digits[k]+1>=10)digits[k--]=0;
if(k>=0) digits[k]+=1;
else digits.insert(digits.begin(),1);
return digits;
};

50. Plus One-Leetcode的更多相关文章

  1. 2019 GOALS

    ANNUAL GOAL 生活 1. 养成早睡早起的习惯 2. 体重:43kg 总体来讲希望自己有一个健康的生活方式,良好的饮食.运动习惯. 2019-04-17 18:47:14 UPDATE 3. ...

  2. [Leetcode][Python]50: Pow(x, n)

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 50: Pow(x, n)https://leetcode.com/probl ...

  3. LeetCode解题录-1~50

    [leetcode]1. Two Sum两数之和 Two Pointers, HashMap Easy [leetcode]2. Add Two Numbers两数相加 Math, LinkedLis ...

  4. [LeetCode] 50. Pow(x, n) 求x的n次方

    Implement pow(x, n), which calculates x raised to the power n(xn). Example 1: Input: 2.00000, 10 Out ...

  5. LeetCode 50. Pow(x, n) 12

    50. Pow(x, n) 题目描述 实现 pow(x, n),即计算 x 的 n 次幂函数. 每日一算法2019/5/15Day 12LeetCode50. Pow(x, n) 示例 1: 输入: ...

  6. LeetCode - 50. Pow(x, n)

    50. Pow(x, n) Problem's Link ----------------------------------------------------------------------- ...

  7. 50. leetcode 520. Detect Capital

    520. Detect Capital Given a word, you need to judge whether the usage of capitals in it is right or ...

  8. 【一天一道LeetCode】#50. Pow(x, n)

    一天一道LeetCode系列 (一)题目 Implement pow(x, n). (二)解题 题目很简单,实现x的n次方. /* 需要注意一下几点: 1.n==0时,返回值为1 2.x==1时,返回 ...

  9. LeetCode(50):Pow(x, n)

    Medium! 题目描述: 实现 pow(x, n) ,即计算 x 的 n 次幂函数. 示例 1: 输入: 2.00000, 10 输出: 1024.00000 示例 2: 输入: 2.10000, ...

  10. LeetCode 50 Pow(x, n) (实现幂运算)

    题目链接:https://leetcode.com/problems/powx-n/?tab=Description   Problem:实现幂运算即 pow(x,n)   设形式为pow(x,n)  ...

随机推荐

  1. react 生命周期 个人见解

    初始化/实例期 gitDefaultprops 获取组件的默认props状态 gitInitialstate 类定义方式或是直接在构造函数中挂载state componentWillMount  组件 ...

  2. TDengine在数益工联工业物联采集平台建设中的初步实践

    作者:易永耀 夏杭泰 邓炜兴 公司介绍 数益工联致力于打造基于数据流+价值流的离散制造业数字化软件:应用新一代的物联网技术与丰富的现场交互手段,融合工业工程精益思想,为离散制造业客户的数字化升级提供从 ...

  3. zuul过滤器filter 的编写

    通过上一节(zuul的各种配置)的学习,我们学会了zuul路由的各种配置,这一节我们来实现一下zuul的过滤器功能.那么为什么需要用到zuul的过滤器呢?我们知道zuul是我们实现外部系统统一访问的入 ...

  4. 热身训练1 Calculator

    题目出处:Calculator 简要题意: 你有一个确定的函数,f(x)=+...*...^...,其中共有n个操作,从左到右依次计算. 共有m次询问,我们每次询问,1.会修改f(x)中的操作:2.输 ...

  5. Python课程笔记(一)

    由于新冠状病毒的爆发,不得不在家里上网课,开课已经两个礼拜了,今天上完Python课后,准备整理一下最近学习Python的笔记. 人生苦短,我用Python 一.Hello World 初学一门新的语 ...

  6. 最详细的windows10系统封装教程

    目录 自定义封装(定制)windows10教程 关于本教程及用到的工具的声明 第一阶段: 封装前的各种环境准备 安装vmware 创建虚拟机 对虚拟机进行分区 配置好BIOS 为虚拟机安装window ...

  7. linux hostid与lmhostid

    https://wangchujiang.com/linux-command/c/hostid.html hostid(host identifier) 显示当前主机的十六进制数字标识. 概要 hos ...

  8. 二进制插入 牛客网 程序员面试金典 C++ Python java

    二进制插入 牛客网 程序员面试金典 题目描述 有两个32位整数n和m,请编写算法将m的二进制数位插入到n的二进制的第j到第i位,其中二进制的位数从低位数到高位且以0开始. 给定两个数int n和int ...

  9. C#笔记2__Char类、String类、StringBuilder类 / 正则表达式 /

    Char类 String类 字符串的格式化:String类的Format方法 StringBuilder类 以上:百度 or 查手册.....

  10. hdu 2058 The sum problem(简单因式分解,,)

    Problem Description Given a sequence 1,2,3,......N, your job is to calculate all the possible sub-se ...