Honestly, this problem might be the easiest one I have solved. Check out the code below, if you get any question, please let me know.
public class Solution {
public int searchInsert(int[] A, int target) {
if(A.length == 0) return 0;
for(int i = 0; i < A.length; i++){
if(A[i] == target) return i;
else{
if(A[i] > target){
return i;
}
}
}
return A.length ;
}
}
Hello, welcome to Yizhe's Blog. I am Yizhe Liu, graduated from University of Arizona, with Master degree, major in Electrical and Computer Engineering. Actually, I am software guy. In my blog, many posts are about the Leetcode questions. I will post my ideas and implementations, which are accepted by Leetcode. If you have different opinions, please leave comment. I am happy to discuss with you. So lets start rocking them!!!
No comments:
Post a Comment