Skip to content

Latest commit

 

History

History
42 lines (36 loc) · 595 Bytes

66.加一.md

File metadata and controls

42 lines (36 loc) · 595 Bytes
title categories
加一
leetcode
leetcode题解
package main

import "fmt"

/*
 * @lc app=leetcode.cn id=66 lang=golang
 *
 * [66] 加一
 */
//  9 9 9 9 9
// @lc code=start
func plusOne(digits []int) []int {

	l := len(digits)
	//遍历数组
	for i := l - 1; i >= 0; i-- {
		digits[i] = (digits[i] + 1) % 10
		fmt.Println(digits[i])
		//判断取模10是否等于零
		if digits[i] != 0 {
			return digits
		}
	}
	//new一个新数组
	newArr := make([]int, l+1)
	// digits= new int[l + 1];
	//设定第一位为1
	newArr[0] = 1
	return newArr

}

// @lc code=end