LeetCode 033 Search in Rotated Sorted Array
2024-10-18 16:10:53
题目要求:Search 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
).
You are given a target value to search. If found in the array return its index, otherwise return -1.
You may assume no duplicate exists in the array.
代码如下:
class Solution {
public:
int search(int A[], int n, int target) { int index = -1; //题目简化成找到数组A中的元素位置……
for(int i = 0; i < n; i++){
if(A[i] == target){
index = i;
break;
}
} return index;
}
};
最新文章
- 基于VC的ACM音频编程接口压缩Wave音频(二)
- 众人口中的JAVASCRIPT
- QListWidget
- fuelux.tree用法
- 遍历对象所有属性(json对象)
- [.NET 即时通信SignalR] 认识SignalR (一)
- 为什么MB51本位币金额和采购订单历史本位币金额不一样?
- Xcode集成Google Test
- Gunner II(二分,map,数字转化)
- 漫谈并发编程(二):java线程的创建与基本控制
- hdu2602 Bone Collector (01背包)
- javaScript属性
- R语言︱决策树族——随机森林算法
- Clean http handlers in Go
- 新建项目到Jenkins中
- SpringBoot启动tomcat源码解读
- mysql的sql语句的性能诊断分析
- [ios]NSThread传值 NSValue传值
- Simple2D-24 Sprite 渲染树
- 利用MessageFormat实现短信模板的匹配
热门文章
- Python列表lists索引关于字符串小纪
- bash中选择结构、循环结构与break、continue
- How to: Debug X++ Code Running in .NET Business Connector [AX 2012]
- IAuthorizationFilter学习笔记(权限控制)以及非全局的filter
- .NET必知的EventCounters性能指标监视器
- Flutter(75):Sliver组件之SliverFixedExtentList
- 一致性(ECMAScript语法标准翻译)
- html中创建并调用vue组件的几种方法
- linux服务器间配置ssh免密连接
- 11.java设计模式之享元模式