lc581

package
v0.0.0-...-b071cee Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2023 License: GPL-3.0 Imports: 2 Imported by: 0

README

581.最短无序连续子数组

1. 题目描述

给你一个整数数组 nums ,你需要找出一个 连续子数组 ,如果对这个子数组进行升序排序,那么整个数组都会变为升序排序。

请你找出符合题意的 最短 子数组,并输出它的长度。

  示例 1:


输入:nums = [2,6,4,8,10,9,15]
输出:5
解释:你只需要对 [6, 4, 8, 10, 9] 进行升序排序,那么整个表都会变为升序排序。

示例 2:


输入:nums = [1,2,3,4]
输出:0

示例 3:


输入:nums = [1]
输出:0

 

提示:

  • 1 <= nums.length <= 10^4
  • -10^5 <= nums[i] <= 10^5  

进阶: 你可以设计一个时间复杂度为 O(n) 的解决方案吗?

标签 贪心 数组 双指针 排序 单调栈

2. 解题

排序或者双指针

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL