博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
LeetCode 581: Shortest Unsorted Continuos Subarray
阅读量:7238 次
发布时间:2019-06-29

本文共 811 字,大约阅读时间需要 2 分钟。

Note:

      end should apply end of left to right order using i index

      start is right to left using length - i - 1 index.

   Set end to be -2 since result is end - start + 1. If nothing found should return 0. So if start is -1, end should be -2.

class Solution {    public int findUnsortedSubarray(int[] nums) {        if (nums.length < 2) {            return 0;        }                int max = nums[0], min = nums[nums.length - 1], start = -1, end = -2;        for (int i = 1; i < nums.length; i++) {            max = Math.max(nums[i], max);            min = Math.min(nums[nums.length - i - 1], min);            if (nums[i] < max) end = i;            if (nums[nums.length - i - 1] > min) start = nums.length - i - 1;        }        return end - start + 1;    }}

 

转载于:https://www.cnblogs.com/shuashuashua/p/7561792.html

你可能感兴趣的文章
mysql数据库的基本操作
查看>>
iOS-自定义Alert框
查看>>
LVS四种负载均衡类型,十种调度方法
查看>>
数据持久化之SQLite
查看>>
android4.1+ ListView 不滚动
查看>>
3. 类
查看>>
Axure快速创建原型的示例
查看>>
ssh连接错误的解决办法
查看>>
mac 下面wireshark 找不到网卡
查看>>
我的友情链接
查看>>
Python 6.3 文档测试
查看>>
mysteel Sql
查看>>
Dockerfile中的权限问题及工作目录问题(USER WORKDIR)
查看>>
c#文件读取和写入的方式总结
查看>>
Djano XSS的转义
查看>>
springMVC项目的web.xml文件
查看>>
基础不牢,地动山摇 - OSI模型
查看>>
You (root) are not allowed to access to (crontab)
查看>>
win7自动换锁屏壁纸
查看>>
web3.py简介
查看>>