棘手的面试问题 [英] Tricky interview question
本文介绍了棘手的面试问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给定两个事件以整数开始和结束时间,E1 =(S1,E1),E2 =(S2,E2),实现一个快速的布尔检查,看是否事件重叠。
我有解决方案,但我很好奇,看看其他人想出。
编辑:好的,这是我的解决方案:
E1> S2 || (S1> S2和放大器;&放大器; E2< S1)
解决方案
布尔重叠=(S1< = E2)及和放大器; (S2< = E1)
Given two events with integer start and end times, E1 = (s1, e1), E2 = (s2, e2), implement a quick boolean check to see if the events overlap.
I have the solution, but I'm curious to see what others come up with.
EDIT: OK, here's my solution:
e1 > s2 || (s1 > s2 && e2 < s1)
解决方案
bool overlap = (s1 <= e2) && (s2 <= e1)
这篇关于棘手的面试问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文