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. 2020BUAA软工个人项目作业

    2020BUAA软工个人项目作业 17373010 杜博玮 项目 内容 这个作业属于哪个课程 2020春季计算机学院软件工程(罗杰 任健) 这个作业的要求在哪里 个人项目作业 我在这个课程的目标是 学 ...

  2. Spring Security 多过滤链的使用

    Spring Security 多过滤链的使用 一.背景 二.需求 1.给客户端使用的api 2.给网站使用的api 三.实现方案 方案一: 方案二 四.实现 1.app 端 Spring Secur ...

  3. [hi3521] nand flash 的 boot 启动模式的区别?

    spi nand flash 的 boot 启动模式选择.0:1 线 boot:1:4 线 boot.请问,1线boot和4线boot有什么区别呢?该如何选择呢?     收藏 顶 踩   回复 使用 ...

  4. nodejs 连接 mysql 查询事务处理

    自己用 mysql 很多次的,然后又是主玩nodejs的.专门写一篇文章来说说nodejs连接mysql数据库.在使用之前,请检查计算机是否具有一下环境! nodejs 执行环境. mysql数据库环 ...

  5. docker+nginx搭建tomcat集群(附录)——nginx.conf文件

    附录:nginx.conf修改后的文件内容 user root;worker_processes 2; #error_log logs/error.log;#error_log logs/error. ...

  6. 如何利用SimpleNVR建立全天候远程视频监控系统

    随着社会经济的发展,5G.AI.云计算.大数据.物联网等新兴技术迭代更新的驱动下,传统的安防监控早已无法满足我们的需求.那么我们如何建立全天候远程视频监控系统来替代传统监控呢?如何进一步优化城市管理. ...

  7. lua入门之环境搭建、第一个demo

    前言 前段时间因为有些项目功能需要,自己研究了下lua,今天整理下,并以一个demo为示例演示 手机上的运行效果 分为几个步骤来逐步讲解. 1.lua介绍,为什么选择它? 2.环境安装 3.撸一个简单 ...

  8. flask 中的endpoint有什么用?

    url到view function之间的一个中间概念,默认是view function的名字,相比于直接使用view function, 使用end point 提供了一个命名空间,可以让不同蓝图的v ...

  9. Emmet快速语法—助力HTML/CSS一行代码一个页面

    学会之后牛掰的场景如下 我们的目标就是用一行代码=>写下面这样的长长长长的HTML结构来. 如:table>(thead.text>th{手机1}*4)+(tbody.text$*4 ...

  10. Python基础(map/reduce)

    from functools import reduce#reduce函数在python3的内建函数移除了,放入了functools模块 #map() list1 = [1,2,3,4,5,6,7,8 ...