How come my solution only beats 17% of the C# submission!?


  • 0
    S

    I don't think any solution would be significantly faster than this.. Can anyone share your algorithm pls?

    public class Solution {

    public int[] PlusOne(int[] digits) {
        for(int i = digits.Length-1; i >= 0; i--){
            if(digits[i] == 9){
                digits[i] = 0;
            }
            else{
                digits[i] = digits[i]+1;
                break;
            }
        }
        if(digits[0] != 0) return digits;
        int[] result = new int[digits.Length+1];
        result[0] = 1;
        return result;
    }
    

    }


Log in to reply
 

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