diff --git a/leetCode Solutions/Q35_Search_Insert_Position/Q35_Search_Insert_Position.java b/leetCode Solutions/Q35_Search_Insert_Position/Q35_Search_Insert_Position.java new file mode 100644 index 0000000..7b4ca5c --- /dev/null +++ b/leetCode Solutions/Q35_Search_Insert_Position/Q35_Search_Insert_Position.java @@ -0,0 +1,29 @@ + + +// We'll first apply the binary search algorithm on the given sorted array. +// If the target value is found, we'll return that index. +// If not, we'll process until our search space becomes empty. At this point, the index at which the element should be inserted is already saved while we dive our search space by half. + + + +class Solution { + public int searchInsert(int[] nums, int target) { + + int s = 0; + int e = nums.length -1; + + while(s<=e){ + int m = (s+e)>>1; + if(target == nums[m]){ + return m; + } + if(target