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 ...
随机推荐
- LOJ2125
LOJ2125 树上操作 题目描述 有一棵点数为 N 的树,以点 1 为根,且树有点权.然后有 M 个操作,分为三种: 把某个节点 x 的点权增加 aa . 把某个节点 x 为根的子树中所有点的点权都 ...
- P95、P99.9百分位数值——服务响应时间的重要衡量指标
前段时间,在对系统进行改版后,经常会有用户投诉说页面响应较慢,我们看了看监控数据,发现从接口响应时间的平均值来看在500ms左右,也算符合要求,不至于像用户说的那么慢,岁很费解,后来观察其它的一些指标 ...
- HTTP1.0/1.1/2.0
https://www.cnblogs.com/heluan/p/8620312.html http缓存策略 https://www.cnblogs.com/Iwillknow/archive/201 ...
- 安装Archlinux+UEFI启动
为了安装Arch自己也走了很多弯路,找了很多教程,最后探索出了这样一个安装方法,不一定适用于每个人. ArchWiki官方安装手册 本方法全程插上网线. 准备 获取镜像 镜像可以从官网获取,访问官方下 ...
- jQuery基础介绍
最近在学习JavaScript,当学习Javascript之后,不得不学习的肯定是jQuery了,所以开始利用网络的便捷浏览各大博客寻找可学习的资源.这篇博客关于jQuery的学习让我有很多收获,也明 ...
- Java项目开发流程()
1项目启动 2需求调研 3系统设计详细设计 4程序开发 5测试 6试用培训维护 项目成员组成 1需求工程师其要求 2系统分析师设计师其要求 3开发工程师其要求 4测试工程师其要求 5管理人员 6其他人 ...
- Spring5源码,Spring DispatecherServlet的生命周期
一.前端控制器模式 二.DispatcherServlet的执行链 三.DispatcherServlet 1.策略初始化 2.请求预处理 3.请求处理 4.视图解析 5.处理调度请求 - 视图渲染 ...
- 2.二层常用技术-Portfast和BPDU Guard、BPDU Filter
PortFast (生成树端口加速) 1.在交换机上使用portfast命令,可以防止出现由于STP的收敛时间太长,导致主机的DHCP请求超时,从而使主机不能接收到DHCP地址的问题. 确保有一台服务 ...
- JDK-7新特性,更优雅的关闭流-java try-with-resource语句使用
前言 公司最近代码质量整改,需要对大方法进行调整,降低到50行以下,对方法的深度进行降低,然后有些文件涉及到流操作,很多try/catch/finally语句,导致行数超出规范值,使用这个语法可以很好 ...
- 用到的API整理
时间 淘宝 http://api.m.taobao.com/rest/api3.do?api=mtop.common.getTimestamp 获取时间戳,调用效果 { "api" ...