今際の国の呵呵君
Tuesday, October 17, 2017
[LeetCode]Output Contest Matches
很直观的题目,我们就按照每一轮来生成结果即可。比如第一轮list中包含(1, n), (2, n - 1)...的序列,那么第二轮我们继续首尾对决,不断更新list直到只剩一个元素即可。时间复杂度O(n),过程就是一个二叉树,总结点数不会超过2 * n。空间复杂度O(n),代码如下:
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment