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

The digits are stored such that the most significant digit is at the head of the list.

Example:

Input:
->-> Output:
->->

思路:递归。

 /**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
int help(ListNode* head) {
if (head->next == NULL) head->val++;
else head->val += help(head->next);
if (head->val < ) return ;
head->val = ;
return ;
}
ListNode* plusOne(ListNode* head) {
int credit = help(head);
if (!credit) return head;
ListNode *res = new ListNode();
res->next = head;
return res;
}
};

最新文章

  1. 【MSSQL】MSSQL还原单mdf文件报1813错误
  2. git submodule 使用
  3. PChar,PAnsiChar,String,AnsiString,Char数组,AnsiChar数组转换
  4. English idioms
  5. NIO组件Selector工作机制详解(上)
  6. Spring入门导读——IoC和AOP
  7. flask 扩展之 -- flask-pagedown
  8. 【java】java.util.regex.Pattern和java.util.regex.Matcher简单示例
  9. 【bird-java】分布式服务间的事件总线EventBus
  10. windows平台上用python 远程线程注入,执行shellcode
  11. Java+Selenium操作日期时间选择框插件
  12. RMQ算法区间最值
  13. C# 引用的程序集没有强名称
  14. jQuery 重复加载,导致依赖于 jQuery的JS全部失效问题
  15. C# 调用 taskkill命令结束服务进程
  16. SQLServer 之 树查询
  17. 技嘉主板+AMD CPU开启CPU虚拟化方法
  18. idea+spring+springmvc+mybatis+mybatis+maven
  19. JSP页面退出时清除会话Session
  20. Debian 安装Linux源码

热门文章

  1. 【ZJ选讲&#183;BZOJ 5073】
  2. MySQL主主搭建
  3. PHP 抽象类,接口,抽象方法,静态方法
  4. ActiveMQ(2) ActiveMQ创建HelloWorld
  5. commons
  6. java replace方法
  7. Spring 学习笔记(一)
  8. 9张图让你明白什么叫做"一坨屎"一样的iOS垃圾代码
  9. bzoj 1011 近似估计
  10. python基础===取txt文件的若干行到另一个文件