-
704. Binary Search javaLeetCode_Study_Plan/Algorithm 2022. 12. 20. 16:01
https://leetcode.com/problems/binary-search/description/?envType=study-plan&id=algorithm-i
class Solution { public int search(int[] nums, int target) { int start = 0; int end = nums.length-1; int idx = -1; while (start <= end) { int mid = (start + end)/2; if (nums[mid] == target) { idx = mid; break; } if (target > nums[mid]) { start = mid + 1; } else { end = mid -1; } } return idx; } }
https://leetcode.com/problems/binary-search/?envType=study-plan&id=algorithm-i
'LeetCode_Study_Plan > Algorithm' 카테고리의 다른 글
🎵 189. Rotate Array java (0) 2022.12.20 977. Squares of a Sorted Array java (0) 2022.12.20 35. Search Insert Position java (0) 2022.12.20 278. First Bad Version java (0) 2022.12.20 [12.20] Algorithm 시작 (0) 2022.12.20