美文网首页
LeetCode之Widest Vertical Area Be

LeetCode之Widest Vertical Area Be

作者: 糕冷羊 | 来源:发表于2020-11-03 17:07 被阅读0次

问题:



方法:
这题最大难点是理解题意。。需要找到横轴距离相距最远的两个点,所以先对points进行排序,然后再遍历得到最大宽度即可。

class WidestVerticalAreaBetweenTwoPointsContainingNoPoints {
    fun maxWidthOfVerticalArea(points: Array<IntArray>): Int {
        var width = 0
        points.sortWith(compareBy { it[0] })
        for (index in 0 until points.lastIndex) {
            if (points[index+1][0] - points[index][0] > width) {
                width = points[index+1][0] - points[index][0]
            }
        }
        return width
    }
}

fun main() {

}

有问题随时沟通

具体代码实现可以参考Github

相关文章

网友评论

      本文标题:LeetCode之Widest Vertical Area Be

      本文链接:https://www.haomeiwen.com/subject/qtkivktx.html