当前位置:网站首页>Judge whether the two time ends contain intersection
Judge whether the two time ends contain intersection
2022-07-20 17:12:00 【Secular big tail bear】
One . introduction
I'm writing a piece of logic today , Judge whether the two time ends contain intersection . Suppose there are two time ends , One is timeA To timeB, The other is timeC To timeD. I drew on the draft book , This is the case :
Then I want to write these situations in code , Although it was finally written , But the process is hard .
The code is as follows ( Regardless of the critical value ):
(timeA.getTime() < timeC.getTime() && timeB.getTime() > timeC.getTime()) ||
(timeA.getTime() > timeC.getTime() && timeA.getTime() < timeD.getTime()
Two . Simple ideas
The above is normal thinking , Then I suddenly thought of the reverse thinking of middle school learning , In fact, it is to judge that there is no intersection between the two time ends , Then reverse it . The following is the case where there is no intersection between the two time ends :
The code is as follows :
timeA.getTime > timeD.getTime || timeB.getTime < timeC.getTime()
The code to judge whether the two time ends contain intersection can be obtained by negating , as follows :
timeA.getTime < timeD.getTime && timeB.getTime > timeC.getTime()
These can be easily judged .( Converse thinking ...)
边栏推荐
- count(1) 比 count(*) 效率高么?
- 完善镜像站配置信息 — 镜像站体验官
- Banyan loan atlas mainly has the following core components, which are customized through rest API
- ProSci阿尔茨海默病 B-淀粉样蛋白检测套装说明书
- Thoroughly uncover how epoll realizes IO multiplexing
- Worthington core enzyme deoxyribonuclease I
- Oom memory overflow is a classic that we have to watch in actual combat
- Characteristics and related applications of Worthington core enzyme papain
- Niuke multi school 1 C grab the seat!
- 【CVA估值训练营】往届优秀学员分享
猜你喜欢
从多线程角度分析QPS、TPS等基础概念
uni-app
Responsive Zhimeng template decoration design website
The advantages and disadvantages of the implementation of ID generator and the principle analysis of the optimal ID generator
GB-CosFace: Rethinking Softmax-based Face Recognition from the Perspectiv从开放集分类的角度重新思考基于Softmax的人脸识别
How does redis analyze slow query operations?
google chrome卸载之后无法安装成功
How can redis and MySQL data be consistent?
Renderdoc 帧调试器
Centernet网络结构搭建
随机推荐
Thoroughly uncover how epoll realizes IO multiplexing
LabView实验——温度检测系统(实验学习版)
Oom Memory overflow a classic That Must See in Real Games
How many rows of data can b+ tree algorithm store in MySQL?
One-vs-rest network-based deep probability model for open set recognition解读
9.进程通信
Deep open intent classification with adaptive decision boundary AAAI2021开放集识别论文解读
用vscode+express创建一个微型WEB服务器
Banyan loan atlas mainly has the following core components, which are customized through rest API
MySQL 之 Explain 输出分析
@Data注解的使用(代替实体类中的get和set方法)
Worthington核心酶——木瓜蛋白酶的特征及相关应用
Worthington core enzyme deoxyribonuclease I
Deeply analyze the underlying implementation principle of serialization and deserialization
文字走马灯
OOM内存溢出实战不得不看的经典
Promise笔记
IDEA的Import changes 和enable auto-import
牛客多校1 C Grab the Seat!
投身自媒体的普通人:他们是如何从从月入30到月入3万的