can anyone tell me why my solution is so slow ?

  • 0

    public class Solution {
    public int[] plusOne(int[] digits) {
    int n=digits.length;
    for(int i=n-1;i>=0;i--){
    if (digits[i] <9){
    digits[i] +=1;
    return digits;

        int[] newNum=new int [n+1];
        newNum[0] += 1; 
        return newNum;


    this should be optimal , right? O(n)
    but I only beats 6% of submissions .
    can this kinda answer satisfy interviewer in real interview ?

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.