Hard-题目10:33. Search in Rotated Sorted Array

转载 2016年05月31日 23:27:13

题目原文:
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.
题目大意:
对一个移位过的,无重复数字的数组,寻找目标数字并返回其下标。如果没有则返回-1.
题目分析:
一开始想到的思路是找到跳变点(即移动点),然后两边都是有序的,再二分查找,但是想不到logn复杂度的,就决定直接无脑找了。
源码:(language:java)

public class Solution {
    public int search(int[] nums, int target) {
        for(int i = 0;i<nums.length;i++)
            if(nums[i]==target)
                return i;
        return -1;
    }
}

源码:
1ms,beats 5.34%,众数1ms,94.64%

LeetCode Algorithms 33. Search in Rotated Sorted Array

题目难度: Medium 原题描述: Suppose an array sorted in ascending order is rotated at some pivot unk...

leetcode-33-Search in Rotated Sorted Array

#include #include using namespace std; class Solution { public: /* 旋转数组只能有三种情况: 1. 左...

Leetcode33 Search in Rotated Sorted Array

Search in Rotated Sorted Array Suppose a sorted array is rotated at some pivot unknown to you befo...

【leetcode】No.33 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 mig...

LeetCode 33 Search in Rotated Sorted Array 题解

题意简述:给定一个按升序排序的数组,这个数组进行了数次旋转(例如数组[0,1,2,4,5,6,7]在2和4之间执行一次旋转就会变成[4,5,6,7,0,1,2]。需要搜索某个数是否在这个数组里面。数组...

leetcode 33. Search in Rotated Sorted Array

1.题目 Suppose a sorted array is rotated at some ...

[Leetcode] 33. 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...

LeetCode 33. Search in Rotated Sorted Array

问题描述: Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 ...

Leetcode 33. Search in Rotated Sorted Array

Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e.,...

【leetcode】33. Search in Rotated Sorted Array

Difficulty:hard Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i....
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Hard-题目10:33. Search in Rotated Sorted Array
举报原因:
原因补充:

(最多只允许输入30个字)