My c# solution,6 line


  • 0
    Z
    public class Solution {
    	public int MissingNumber(int[] nums) {
    		int length = nums.Length;
    		int sum = (length) * (length + 1) / 2;
    		for (int i=0; i<length; i++) {
    			sum-=nums[i];
    		}
    		return sum;
    	}
    }

Log in to reply
 

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