Discuss / Java / 做差法合并为一次循环

做差法合并为一次循环

Topic source

不容艺

#1 Created at ... [Delete] [Delete and Lock User]
	static int findMissingNumber(int start, int end, List<Integer> list) {
		int total = 0;
		int count = 0;
		for(Integer element:list) {
			count += element;
			total += (start++);
		}
		total += start;
		return total-count;
	}

  • 1

Reply