Created
May 12, 2014 06:46
-
-
Save Cee/4f92d12d254dd5ca8ce8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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