Search in Rotated Sorted Array(在一个旋转的排序数组以O(logN)查找目标数)leetcode32

Suppose an array sorted in ascending order 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.

Your algorithm's runtime complexity must be in the order of O(log n).

Example 1:

Input: nums = [4,5,6,7,0,1,2], target = 0
Output: 4

Example 2:

Input: nums = [4,5,6,7,0,1,2], target = 3
Output: -1

code1:

O(n)

 public int search(int[] nums, int target) {
        for(int i = 0; i< nums.length; i++){
            if( target == nums[i]){
                return i;
            }
        }
        return -1;
    }
### 推荐的Linux系统BT客户端 对于Linux用户来说,有多个优秀的BitTorrent客户端可供选择。以下是几个推荐选项: #### 1. qBittorrent qBittorrent是一个开源且跨平台的轻量级BitTorrent客户端。它具有直观的图形界面,并支持多种高级功能。 - 支持磁力链接和RSS自动下载。 - 提供带宽调度器以及Web UI远程管理。 - 可以通过插件扩展其功能。 安装方法如下: ```bash sudo apt update && sudo apt install qbittorrent ``` #### 2. Transmission Transmission是一款专为Mac OS X设计但同样适用于Linux环境下的BitTorrent客户端。它的特点是占用资源少、易于配置并且安全性高。 - 用户界面简洁友好。 - 内置加密传输协议保护隐私。 - 自动更新种子文件列表并清理已完成的任务。 安装命令为: ```bash sudo apt-get install transmission-gtk ``` #### 3. Deluge Deluge是另一个流行的Python编写的自由软件项目之一,在Linux社区中有很高的人气。除了基本的功能外,还提供了丰富的第三方插件来增强用户体验。 - 多种通知方式(如桌面提示、电子邮件等)。 - 能够设置不同的优先级给各个文件片段。 - 完全自定义化的队列管理系统。 可以通过以下指令获取最新版本: ```bash sudo add-apt-repository ppa:deluge-team/ppa sudo apt-get update sudo apt-get install deluge ``` 以上三个都是目前较为流行且稳定的LinuxBT客户端解决方案[^1]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值