2017年12月11日

Leetcode: 2. Add Two Numbers

摘要: 一直想用一个进位变量来存贮进位值,但老是考虑不周全,下面是我自己写的bug代码,考虑不周,因为l1或者l2都有可能为null acccpt:https://discuss.leetcode.com/topic/799/is-this-algorithm-optimal-or-what 阅读全文

posted @ 2017-12-11 21:15 Michael2397 阅读(124) 评论(0) 推荐(0) 编辑

Leetcode:560. Subarray Sum Equals K

摘要: 最简单的方式,虽然oj没有说超时,但是时间还是挺多的 本次的方法是遍历所有起点是最开始元素的子序列,我们起名叫sum[i],只要两个sum[i]的差值是k,则两个i作为起点和终点的子序列就符合要求。由于起点就是最开始元素,只需遍历终点,时间复杂度为O(n)。 阅读全文

posted @ 2017-12-11 20:13 Michael2397 阅读(139) 评论(0) 推荐(0) 编辑

Leetcode: 653. Two Sum IV - Input is a BST

摘要: 超时代码:只多了一个bool变量就超时了 accpt的代码,把二叉树前序遍历得到list,顺序是从小到大排列的 阅读全文

posted @ 2017-12-11 09:48 Michael2397 阅读(126) 评论(0) 推荐(0) 编辑

Leetcode: 167. Two Sum II - Input array is sorted

摘要: 超时的代码: Accept代码:如果数组已经排好序了,就尽可能的使用while(),左右遍历 阅读全文

posted @ 2017-12-11 09:14 Michael2397 阅读(98) 评论(0) 推荐(0) 编辑

Leetcode:454. 4Sum II

摘要: 参考:https://discuss.leetcode.com/topic/67658/simple-java-solution-with-explanation 阅读全文

posted @ 2017-12-11 08:59 Michael2397 阅读(102) 评论(0) 推荐(0) 编辑

LeetCode: 18. 4Sum

摘要: 递归调用的例子,参考网上的实现https://discuss.leetcode.com/topic/46339/my-solution-generalized-for-ksums-in-java/5 阅读全文

posted @ 2017-12-11 00:46 Michael2397 阅读(120) 评论(0) 推荐(0) 编辑

导航