Discuss / Java / 打卡

打卡

Topic source

_vfgj_

#1 Created at ... [Delete] [Delete and Lock User]
1.static int findMissingNumber(int start, int end, List<Integer> list) {
           List<Integer> lists = new ArrayList<>();
           for(int i=start; i <= end;i++) {
                lists.add(i);
           }
           for(Integer n : lists) {
                if(list.contains(n)==false) {
                     return n;
                }
           }
           return 0;
     }
}

2.static int findMissingNumber(int start, int end, List<Integer> list) {
           for(Integer i : list) {
                if( i != start) {
                     return start;
                }
                start++;
           }
           return 0;
     }

2中方法只适用于有序,1中方法适用于有序和无序


  • 1

Reply