标签:
class Solution { public int solution(int[] A) { // write your code in Java SE 8 if(A.length<2){ return 0; }else{ int sorted[] = bubbleSort(A); for(int i=0;i<sorted.length;i++){ if(i==sorted.length-1){ return 0; }else{ int difference = sorted[i+1]-sorted[i]; if(difference==2){ return sorted[i]+1; } } } } return 0; } public int[] bubbleSort(int[] number) { int temp = 0; for (int i = 0; i < number.length - 1; i++){ for (int j = 0; j < number.length - 1 - i ; j++){ if (number[j] > number[j + 1]) { temp = number[j]; number[j] = number[j + 1]; number[j + 1] = temp; } //if end } } return number; } }
标签:
原文地址:http://www.cnblogs.com/visionary/p/4558384.html