shit leetcode edge testcases
shit leetcode edge testcases
- Merge Intervals
try
"use strict";
/**
*
* @author xgqfrms
* @license MIT
* @copyright xgqfrms
* @created 2020-11-26
* @modified
*
* @description 56. Merge Intervals
* @description 56. 合并区间
* @difficulty Medium
* @complexity O(n)
* @time O(n)
* @augments
* @example
* @link https://leetcode.com/problems/merge-intervals/
* @link https://leetcode-cn.com/problems/merge-intervals/
* @solutions
*
* @best_solutions
*
*/
const log = console.log;
/**
* @param {number[][]} intervals
* @return {number[][]}
*/
var merge = function(intervals) {
const result = [];
if(intervals.length < 2) {
return intervals || [];
}
// sort
intervals.sort(([a0], [b0]) => a0 > b0 ? 1 : -1);
const map = new Map();
let temp = intervals[0];
for (let i = 1; i < intervals.length; i++) {
// [[1,3],[2,6],[8,10],[15,18]]
const [t0, t1] = temp;
const [a0, a1] = intervals[i];
// log(`t0, t1 =`, t0, t1)
// log(`a0, a1 =`, a0, a1)
if(a0 <= t1 && a1 > t1) {
// merge
result.push([t0, a1]);
map.set(JSON.stringify([t0, a1]))
temp = [t0, a1];
} else if (a0 > t1) {
// 重复 bug
if(!map.has(JSON.stringify([t0, t1]))) {
result.push([t0, t1]);
map.set(JSON.stringify([t0, t1]))
}
result.push([a0, a1]);
map.set(JSON.stringify([a0, a1]))
temp = [a0, a1];
} else {
result.push([a0, a1]);
map.set(JSON.stringify([a0, a1]))
temp = [a0, a1];
}
}
return result;
};
const intervals = [[1, 3], [2, 6], [8, 10], [ 15, 18]];
const test = merge(intervals);
log(`test =`, test);
// [[1, 6], [8, 10], [15, 18]]
log(`test =`, JSON.stringify(test) === JSON.stringify([[1, 6], [8, 10], [15, 18]]) ? `` : ``);
const intervals2 = [[1, 4], [4, 5]];
const test2 = merge(intervals2);
log(`test2 =`, test2);
// [[1, 5]]
log(`test =`, JSON.stringify(test2) === JSON.stringify([[1,5]]) ? `` : ``);
const intervals3 = [[1, 4], [5, 6]];
const test3 = merge(intervals3);
log(`test3 =`, test3);
// [[1,4],[5,6]]
log(`test =`, JSON.stringify(test3) === JSON.stringify([[1,4],[5,6]]) ? `` : ``);
const intervals4= [[1, 4], [0, 1]];
const test4 = merge(intervals4);
log(`test4 =`, test4);
// [[0,4]]
log(`test =`, JSON.stringify(test4) === JSON.stringify( [[0,4]]) ? `` : ``);
const intervals5= [[1, 4], [1, 5]];
const test5 = merge(intervals5);
log(`test5 =`, test5);
// [[1,5]]
log(`test =`, JSON.stringify(test5) === JSON.stringify([[1,5]]) ? `` : ``);
https://leetcode.com/problems/merge-intervals/
https://leetcode-cn.com/problems/merge-intervals/submissions/
refs
https://github.com/LeetCode-Feedback/LeetCode-Feedback/issues/1457
xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
shit leetcode edge testcases的更多相关文章
- NOI前的考试日志
4.14 网络流专项测试 先看T1,不会,看T2,仙人掌???wtf??弃疗.看T3,貌似最可做了,然后开始刚,刚了30min无果,打了50分暴力,然后接着去看T1,把序列差分了一下,推了会式子,发现 ...
- [LeetCode] Number of Connected Components in an Undirected Graph 无向图中的连通区域的个数
Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), ...
- [LeetCode] Minimum Height Trees 最小高度树
For a undirected graph with tree characteristics, we can choose any node as the root. The result gra ...
- [LeetCode] Integer to English Words 整数转为英文单词
Convert a non-negative integer to its english words representation. Given input is guaranteed to be ...
- [LeetCode] Graph Valid Tree 图验证树
Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), ...
- [LeetCode] The Skyline Problem 天际线问题
A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...
- [LeetCode] The Skyline Problem
A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...
- Leetcode: Matchsticks to Square && Grammar: reverse an primative array
Remember the story of Little Match Girl? By now, you know exactly what matchsticks the little match ...
- Palindrome Pairs -- LeetCode 336
Given a list of unique words. Find all pairs of distinct indices (i, j) in the given list, so that t ...
随机推荐
- pytest:conftest.py文件
一.fixture scope 为session 级别是可以跨 .py模块调用的,也就是当我们有多个 .py文件的用例时,如果多个用例只需调用一次fixture,可以将scope='session', ...
- Linux下pcstat安装踩坑教程
首先安装golang 1.进入官方链接下载对应自己系统版本的Golang安装包:https://dl.google.com/go/go1.13.4.linux-amd64.tar.gz root@ub ...
- Apache Http Server 一些资料
配置虚拟主机的例子: http://httpd.apache.org/docs/current/vhosts/examples.html
- 理解前端模块概念:CommonJs与ES6Module
前言 现代前端开发每时每刻都和模块打交道.例如,在项目中引入一个插件,或者实现一个供全局使用组件的JS文件.这些都可以称为模块. 在设计程序结构时,不可能把所有代码都放在一起.更为友好的组织方式时按照 ...
- 11月份 chrome 标签整理
Spring MVC框架相关 Java Web开发 和 linux下开发 汇总 项目源码 优秀的音视频开源框架 常用软件的下载 学习资源或网站 最后分享一些以前收藏的优秀博客 这两天经过3次面试,很幸 ...
- Kafka客户端Producer与Consumer
Kafka客户端Producer与Consumer 一.pom.xml 二.相关配置文件 producer.properties log4j.properties base.properties 三. ...
- 华三交换机NTP配置
clock protocol ntp ntp-service enable ntp-service unicast-server x.x.x.x clock timezone beijing add ...
- NoSQL:一个帝国的崛起
01关系数据库帝国 现在是公元2009年,关系帝国已经统治了我们30多年,实在是太久了. 1970年,科德提出关系模型,1974年张伯伦和博伊斯制造出了SQL ,帝国迅速建立起了统治. 从北美到欧洲, ...
- maven基础学习-为什么要用maven,帮助解决了什么问题,怎么解决的,希望以后学习每个知识点都可以这样问下自己
maven基础学习 第1章 Maven介绍 1.1 什么是Maven 1.1.1 什么是Maven Maven 的正确发音是[ˈmevən],而不是"马瘟"以及其他什么瘟.Mave ...
- Jenkins(2)docker容器中安装python3
前言 使用docker安装jenkins环境,jenkins构建的workspace目录默认是在容器里面构建的,如果我们想执行python3的代码,需进容器内部安装python3的环境. 进jenki ...