Skip to content

Instantly share code, notes, and snippets.

@Cee
Created May 12, 2014 06:46
Show Gist options
  • Save Cee/4f92d12d254dd5ca8ce8 to your computer and use it in GitHub Desktop.
Save Cee/4f92d12d254dd5ca8ce8 to your computer and use it in GitHub Desktop.
public class Solution {
public int searchInsert(int[] A, int target) {
int i = 0;
if (target < A[i]) return 0;
if (target > A[A.length - 1]) return A.length;
while ((target >= A[i]) || (i + 1 <= A.length)){
if (target == A[i]){
return i;
}
if ((target > A[i]) && (target < A[i + 1])){
return i + 1;
}
i++;
}
return i;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment