leetcode 总结,记录,备忘。153
来源:互联网 发布:手机荧光灯软件 编辑:程序博客网 时间:2024/06/05 15:56
leetcode153。。。
Find Minimum in Rotated Sorted Array
Suppose a sorted array is rotated at some pivot unknown to you beforehand.
(i.e., 0 1 2 4 5 6 7
might become 4 5 6 7 0 1 2
).
Find the minimum element.
You may assume no duplicate exists in the array.
啊啊,,这个题,,,,我直接耍赖了,,,,,直接把vector里的东西放入set里面了,,然后返回第一个值。。。。。。感觉有点投机取巧,,虽然造好的轮子就应该熟练使用。。。。
class Solution {public: int findMin(vector<int>& nums) { set<int> si(nums.begin(), nums.end()); return *si.begin(); }};刚写到这,我又回头翻了下题目的小tags,提示使用二分法,的确,因为如过一段排序的数组随意截断再接到后面的话,后一段的任何一个数都比前一段的数小,于是使用二分法,先找中点然后判断中点是否小于最前面的数,如果小的话,留下前半段,继续二分,因为最小的数一定留在这一段中。
可能我这段话描述的不是很清楚,,说的也可能不是很对,,但感觉还是有点理可寻,,,我再去看看别人的写法。。。
0 0
- leetcode 总结,记录,备忘。153
- leetcode刷题。总结,记录,备忘 104
- leetcode刷题。总结,记录,备忘 100
- leetcode刷题。总结,记录,备忘 191
- leetcode刷题。总结,记录,备忘。168
- leetcode刷题, 总结,记录,备忘 171
- leetcode刷题 ,总结,记录,备忘。144
- leetcode刷题,总结,记录, 备忘 141
- leetcode刷题,总结,记录,备忘。116
- leetcode刷题,总结,记录,备忘。96
- leetcode刷题。记录,总结,备忘。217
- leetcode 刷题, 总结,记录,备忘 35
- leetcode刷题,总结,记录,备忘 226
- leetcode刷题,总结,记录,备忘 169
- leetcode刷题,总结,记录,备忘137
- leetcode刷题,总结,记录,备忘83
- leetcode刷题,总结,记录,备忘70
- leetcode 刷题目,总结,记录,备忘 13
- Module.h 网狐的“com”工具箱
- J2EE之JDBC
- 封装顶部选择按钮(用block实现在当前控制器下面添加button点击方法)
- Tween算法及缓动效果
- html学习笔记
- leetcode 总结,记录,备忘。153
- 大厅的列表服务预览
- LeetCode Word Search
- OCSP server in Windows2012R2 详细搭建过程
- 最常用的字
- oracle 2
- DWZ(三):常用组件了解
- 在命令行状态下,如何运行编译后的.class 文件???
- Python学习十四:filter()