*LeetCode-Find Peak Element
来源:互联网 发布:网络渗透 视频 编辑:程序博客网 时间:2024/05/24 07:17
brute force每个和后面的数字比 找到不增长的那个 o(n)
public class Solution { public int findPeakElement(int[] nums) { if ( nums == null || nums.length < 2) return 0; for ( int i = 0; i < nums.length - 1; i ++ ){ if ( nums[i+1] < nums[i] ) return i; } return nums.length-1; }}
binary search logn
public class Solution { public int findPeakElement(int[] nums) { if ( nums == null || nums.length < 2) return 0; int high = nums.length-1; int low = 0; while ( low < high ){ int mid = ( low + high ) /2; int mid2 = mid + 1; if ( nums[mid2] > nums[mid] ){ low = mid2; } else high = mid; } return low; }}
0 0
- [LeetCode] Find Peak Element
- Leetcode:Find Peak Element
- LeetCode Find Peak Element
- leetcode: Find Peak Element
- leetcode:Find Peak Element
- LeetCode Find Peak Element
- Find Peak Element --leetcode
- Leetcode Find Peak Element
- [LeetCode] Find Peak Element
- Leetcode Find Peak Element
- Leetcode: Find Peak Element
- 【leetcode】Find Peak Element
- leetcode:Find Peak Element
- 【Leetcode】Find Peak Element
- LeetCode:Find Peak Element
- LeetCode:Find Peak Element
- [LeetCode] Find Peak Element
- LeetCode Find Peak Element
- Raising Bacteria (Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] )
- lintcode做题总结, Sept 16
- 条款34:区分接口继承和实现继承
- mac:su Password: su: Sorry
- CPP-类定义(Class definitions)
- *LeetCode-Find Peak Element
- 3 sequence containers in STL
- docker mysql 主从配置
- LeetCode-Spiral Matrix
- LeetCode-Spiral Matrix II
- Ubuntu 15搭建下HHVM Nginx环境
- 写个Unix的diff命令的简化版本
- 条款35:考虑virtual函数以外的其他选择
- SpriteBuilder中的CCB Node尺寸