Missing Ranges

2024-01-04 12:58
文章标签 missing ranges

本文主要是介绍Missing Ranges,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

我们就用种最朴素的解法就好,bug free,考虑不同的Corner case

public class Solution {public List<String> findMissingRanges(int[] nums, int lower, int upper) {List<String> result = new LinkedList<>();if (nums.length == 0) {if (lower != upper) {result.add(Integer.toString(lower) + "->" + upper);} else {result.add(Integer.toString(lower));}return result;}if (lower < nums[0]) {if (lower == nums[0] - 1) {result.add(Integer.toString(lower));} else {result.add(Integer.toString(lower) + "->" + Integer.toString(nums[0] - 1));}}for (int i = 0; i < nums.length - 1; i++) {if (nums[i + 1] - nums[i] == 2) {result.add(Integer.toString(nums[i] + 1));} else if (nums[i + 1] - nums[i] > 2) {result.add(Integer.toString(nums[i] + 1) + "->" + Integer.toString(nums[i + 1] - 1));}}if (upper > nums[nums.length - 1]) {if (upper == nums[nums.length - 1] + 1) {result.add(Integer.toString(upper));} else {result.add(Integer.toString(nums[nums.length - 1] + 1) + "->" + Integer.toString(upper));}}return result;}
}


这篇关于Missing Ranges的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/569400

相关文章

code: 400, msg: Required request body is missing 错误解决

引起这个错误的原因是,请求参数按照get方式给。 应该给json字符串才对 补充: 1. @RequestBody String resource 加@RequestBody必须给json字符串,否则会报错400,记如标题错误。 不加这个的进行请求的话,其实post和get就没有什么区别了。 2. List<String> indexCodes=(List<String>)json.

Vue3+Vite+Echarts 出现Missing semicolon错误

使用的echarts代码如下:   import * as echarts from 'echarts';type EChartsOption = echarts.EChartsOption;var chartDom = document.getElementById('main')!;var myChart = echarts.init(chartDom);var option: ECha

LeetCode - 41. First Missing Positive

41. First Missing Positive  Problem's Link  ---------------------------------------------------------------------------- Mean:  给你一组整数,找出第一个空缺的正整数. 要求:时间O(n),空间O(n). analyse: 这题时间O(n)想了

Missing Pages

题目描述 Long ago, there were periodicals called newspapers, and these newspapers were printed on paper, and people used to read them, and perhaps even share them. One unfortunate thing about this for

Missing Purpose String in Info.plist File:构建版本按钮不显示.

最近做了一个新项目,打包发布的时候,等了好长时间,构建版本的按钮就是不出现,后来登录开发者账号的邮箱,才看见苹果发过来的邮件: Dear Developer, We identified one or more issues with a recent delivery for your app, "蓝汇智能AI". Please correct the following issues, t

keras missing label unlabeled 未标注类 如何训练 如何自定义损失函数 去除未标注类 缺少标签

我从这里找到的答案: def ignore_unknown_xentropy(ytrue, ypred):return (1-ytrue[:, :, :, 0])*categorical_crossentropy(ytrue, ypred) 然后下面是我的代码: 我感觉看到这个帖子的应该都看得懂吧(其实就是懒得解释了,请看注释)  from __future__ import print_

java.lang.IllegalStateException: aidl is missing

从windows电脑上面切换到Mac上面经历了一些列的问题呀。。。关键问题还是sdk,gradle,版本不全的问题,缺这少那的。奈何下载又不给力,头大,最后终于是好了。 先来说下这个问题吧:java.lang.IllegalStateException: aidl is missing,这个问题是因为我的 compileSdkVersion buildToolsVersion targetSdk

【Maven】dependencies.dependency.version is missing 问题

子模块为web项目,在写依赖时,没有写version的信息。在父pom中使用dependencyManagement中写明了version 于是pom报错:dependencies.dependency.version is missing 原因及解决办法: 1、 maven 对于父项目定义的dependencyManagement 中的 非 jar 类型的 type节点不会继承,也就是说子

GEE错误:Property ‘species_ID‘ of feature ‘0_0‘ is missing.

目录 错误 数据属性 现有的属性信息 原始代码  错误解析 已经写过的博客 错误 Image (Error) Property 'species_ID' of feature '0_0' is missing. 数据属性 现有的属性信息   原始代码 var sp = ee.FeatureCollection("projects/ee-aptiawo

装过mr又卸载了,max报错 mrmateralattribs missing dlls

rendering>scene converter 打开对话框后,current preset 中选择 remove invalid legacy elements,取消open scene converter。。勾选 automaticaly remove missing。再点 convet scene