p133 查找数组的波峰(leetcode 162)

Time:O(log(n)),Space:O(1)

C++:

```class Solution {
public:
int findPeakElement(vector<int>& nums)
{
if (nums.size() == 0) return -1;
int minValue = -2147483648;
int low = 0, high = nums.size() - 1;
while (low < high)
{
int mid = low + (high-low) / 2;
int left = mid - 1 >= 0 ? nums[mid - 1] : minValue;
int right = mid + 1 < nums.size() ? nums[mid + 1] : minValue;
if (nums[mid] > left && nums[mid] > right) return mid;
else if (left > nums[mid]) high = mid - 1;
else low = mid + 1;
}

return low;
}
};```

Java:

```class Solution {
public int findPeakElement(int[] nums)
{
if(nums==null || nums.length==0) return -1;
int low=0,high=nums.length-1;
while (low<high)
{
int mid=low+(high-low)/2;
int left=mid-1>=0?nums[mid-1]:Integer.MIN_VALUE;
int right=mid+1<nums.length?nums[mid+1]:Integer.MIN_VALUE;
if(nums[mid]>left && nums[mid]>right) return mid;
else if(left>nums[mid]) high=mid-1;
else low=mid+1;
}

return low;
}
}```

动态数组，数组初始化，数组内存释放，向数组中添加一个元素，向数组中添加多个元素，数组打印，顺序查找，二分查找，查找数组并返回地址，冒泡排序，改变数组中某个元素的值，删除一个数值，删除所有，查找含有

﻿﻿ 1定义接口: Num.h #ifndef_NUM_H_ #define_NUM_H_ #include<stdio.h> #include<stdlib.h> /************************************************************************/ /*数组的结构体类型                                                    */ /*******************

【题解】【数组】【Leetcode】Median of Two Sorted Arrays

Median of Two Sorted Arrays There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

php 查找数组中是否存在某项，并返回指定的字符串，可用于检查复选，单选等

/** * 查找数组中是否存在某项,并返回指定的字符串,可用于检查复选,单选等 * @param \$id * @param \$ids * @param string \$returnstr * @return string */ function check_in(\$id,\$ids,\$returnstr = 'checked') { if(in_array(\$id,\$ids)) return \$returnstr; }

php折半查找(数组必须为有序)

\$arr=array('1','7','9','11','20','23','33','44','50');     \$len=count(\$arr);      \$low=0;\$high=\$len-1;         while(\$low<\$high)    {                  \$mid=intval((\$low+\$high)/2);        echo \$mid.'<br/>';         if(\$arr[\$mid]>9)         {

解析、查找数组中重复出现的元素（Java）

﻿﻿ 解析.查找数组中重复出现的元素,Java实现. <数据结构与算法分析:解析.查找数组中重复出现的元素> 问题描述:一个结构化数据,假设事先按照某种顺序排好序(比如升序)的一个数组中,无规则.重复出现若干次某个相同元素,形如有序数组data: data = {  "A", "A", "B", "C", "C", "D", "D" , "D&q