GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Leetcode-Java/leetcode/solution/src/SearchInsertPosition.java at master · Tulpen/Leetcode-Java Expand file tree/ Copy pathSearchInsertPosition.javaMore file actions 27 lines (21 loc) · 675 Bytes / Copy pathSearchInsertPosition.javaFile metadata and controls27 lines (21 loc) · 675 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 import java.util.Arrays; public class SearchInsertPosition { public int searchInsert(int[] nums, int target) { int left = 0, right = nums.length - 1; while (left <= right) { int mid = (left + right) / 2; if (target == nums[mid]) { return mid; } else if (target > nums[mid]) { left = mid + 1; } else { right = mid - 1; } } return left; } public int searchInsert2(int[] nums, int target) { int index = Arrays.binarySearch(nums, 0, nums.length, target); return index >= 0 ? index : -(index + 1); } } |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |