Skip to content

Latest commit

 

History

History
70 lines (50 loc) · 1.08 KB

[0369] 给单链表加一.md

File metadata and controls

70 lines (50 loc) · 1.08 KB
title tags categories author comments updated permalink mathjax top description date
[0369] 给单链表加一
leetcode
leetcode
张学志
true
false
false
false
...
2019-12-31 16:06:09 -0800

题目描述

用一个 非空 单链表来表示一个非负整数,然后将这个整数加一。

你可以假设这个整数除了 0 本身,没有任何前导的 0。

这个整数的各个数位按照 高位在链表头部低位在链表尾部 的顺序排列。

示例:

输入: [1,2,3]
输出: [1,2,4]
Related Topics
  • 链表
  • 题目代码

    /**
     * Definition for singly-linked list.
     * struct ListNode {
     *     int val;
     *     ListNode *next;
     *     ListNode(int x) : val(x), next(NULL) {}
     * };
     */
    class Solution {
    public:
        ListNode* plusOne(ListNode* head) {
    
        }
    };

    题目解析

    方法一

    方法二

    方法三