Skip to content

Leetcode - 66. Plus One  #3

@vitabyfrank

Description

@vitabyfrank
  • Because if the result is more than 18 digits it will only add zero which in some testcases it is a wrong result
// Wrong 
// const num = +digits.join("") + 1
// const arr = Array.from(String(num))
/**
 * @param {number[]} digits
 * @return {number[]}
 */

// const num = +digits.join("") + 1
// const arr = Array.from(String(num))
  
var plusOne = function(digits) {
    let number = BigInt(digits.join(""))
    let numOne = number+BigInt(1)
    return Array.from(String(numOne))
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions