Skip to content

Instantly share code, notes, and snippets.

@Maggie199
Created January 21, 2015 22:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Maggie199/35532cf4c604ba306ba1 to your computer and use it in GitHub Desktop.
Save Maggie199/35532cf4c604ba306ba1 to your computer and use it in GitHub Desktop.
Leetcode #35
public int searchInsert(int[] A, int target) {
for(int i=0;i<A.length;i++){
if(A[i] == target)
return i;
else if(A[i] > target)
return i;
else if(i == A.length-1)
return i+1;
}
return -1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment