public static void main(String[] args){ //创建一个int数组,长度为100, int n = 100; int[] arrayInt = new int[n]; Random random = new Random(); ArrayList myList = new ArrayList(); while(myList.size() < 100){ //随机函数生成0-100的整数 int num = random.nextInt(101); //myLi
Given an array of integers nums sorted in ascending order, find the starting and ending position of a given target value. Your algorithm's runtime complexity must be in the order of O(log n). If the target is not found in the array, return [-1, -1].
Given an array of integers nums sorted in ascending order, find the starting and ending position of a given target value. Your algorithm's runtime complexity must be in the order of O(log n). If the target is not found in the array, return [-1, -1].
题目链接 [题解] 二分某个数的上下界. 其实这个方法并不难. 只要你想清楚了二分最后一次执行的位置在什么地方就不难了. [代码] class Solution { public: vector<int> searchRange(vector<int>& nums, int target) { vector<int> ans;ans.clear(); int len = nums.size(); int l = 0,r = len-1; while (l<