zoukankan      html  css  js  c++  java
  • leetCode 81.Search in Rotated Sorted Array II (旋转数组的搜索II) 解题思路和方法

    Follow up for "Search in Rotated Sorted Array":
    What if duplicates are allowed?

    Would this affect the run-time complexity? How and why?

    Write a function to determine if a given target is in the array.


    思路:此题在解的时候,才发现Search in Rotated Sorted Array的时候想复杂了,事实上仅仅须要遍历搜索就可以,线性时间。

    代码例如以下:

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



  • 相关阅读:
    事件基础
    DOM
    GoWeb编程之多路复用
    GoWeb编程之HelloWorld
    Linux libtins 库安装教程
    模式串匹配KMP详解
    树的重心
    Light OJ 1064
    Light OJ 1060
    1057
  • 原文地址:https://www.cnblogs.com/wzzkaifa/p/6902363.html
Copyright © 2011-2022 走看看