容易的面试问题变得更加困难:给定数字1..100,在正好缺少k的情况下,找到缺失的数字
问题: I had an interesting job interview experience a while back. 前一段时间我有一次有趣的面试经历。 The question started really easy: 这个问题开始很容易: Q1 : We have a bag containing numbers 1 , 2 , 3 , …, 100 . Q1: 我们有一个包含数字的包 1 , 2 , 3 ,..., 100 。 Each number appears exactly once, so there are 100 numbers. 每个数字仅出现一次,因此有100个数字。 Now one number is randomly picked out of the bag. 现在,从袋子中随机抽取一个号码。 Find the missing number. 查找丢失的号码。 I've heard this interview question before, of course, so I very quickly answered along the lines of: 我当然已经听过这个面试问题,所以我很快就回答了以下问题: A1 : Well, the sum of the numbers 1 + 2 + 3 + … + N is (N+1)(N/2