lintcode-medium-Find the Missing Number
Posted 哥布林工程师
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了lintcode-medium-Find the Missing Number相关的知识,希望对你有一定的参考价值。
Given an array contains N numbers of 0 .. N, find which number doesn‘t exist in the array.
public class Solution { /** * @param nums: an array of integers * @return: an integer */ public int findMissing(int[] nums) { // write your code here if(nums == null || nums.length == 0) return 0; int sum = 0; for(int i = 0; i < nums.length; i++){ sum += nums[i]; } int N = nums.length; return N * (N + 1) / 2 - sum; } }
以上是关于lintcode-medium-Find the Missing Number的主要内容,如果未能解决你的问题,请参考以下文章
lintcode-medium-Find Minimum in Rotated Sorted Array II
The goddess, the bird, the bell, the temptation of the house
Read the ads,Match the titles with the
simplify the design of the hardware forming the interface between the processor and thememory system
Word2010 Error:The name in the end tag of the element must match the element type in the start tag.
Word2010 Error:The name in the end tag of the element must match the element type in the start tag.