美文网首页
3 sum closest

3 sum closest

作者: 世界你好 | 来源:发表于2018-06-19 11:18 被阅读11次

    3 sum 的变形题

    Solution1:

    sort first, then iterate the array, fix one element,  using two pointer to calculate the sum for 3 elements, using absolute value to determine which is the closest result.

    time: O(n^2), space: O(1)

    相关文章

      网友评论

          本文标题:3 sum closest

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