gpt4 book ai didi

algorithm - 为什么 Interval.contains(Interval) 需要包含 other.start < this.end 条件?

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:35:58 29 4
gpt4 key购买 nike

在 Joda-Time 中, Interval.contains(Interval) 的实现看起来像这样:

return (thisStart <= otherStart && otherStart < thisEnd && otherEnd <= thisEnd);

我无法理解为什么第二部分 otherStart < thisEnd是需要的,我。 e.为什么不

thisStart <= otherStart && otherEnd <= thisEnd

足够了。

最佳答案

这是注释中解释的特殊情况,以避免将持续时间为 0 (start == end) 的 other 间隔定位在 thisEnd

包含

thisStart时间,不包含thisEnd时间

[09:00 to 10:00) contains [10:00 to 10:00) = false (otherStart equals thisEnd)

    this                 --+
|----------| +--- not contained
| <-- other --+

this --+
|----------| +--- contained
| <-- other --+


this --+
|----------| +--- contained
| <-- other --+

关于algorithm - 为什么 Interval.contains(Interval) 需要包含 other.start < this.end 条件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55948573/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com