Discuss / Java / 因为不知道有contains所以选择了剔除法

因为不知道有contains所以选择了剔除法

Topic source

黯然

#1 Created at ... [Delete] [Delete and Lock User]

自己构造一个数组后剔除已有的,最后返回剩下的

static int findMissingNumber(int start, int end, List<Integer> list) {
		Integer[] lis = new Integer[end - start + 1];
		for (int i = start; i <= end; i++) {
			lis[i - start] = i;
		}
		for (Integer one : list) {
			lis[one - start] = null;
		}
		int i = -1;
		for (Integer k : lis) {
			if (k != null)
				i = (int) k;
		}
		return i;
	}

  • 1

Reply