![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Leetcode
haifengyululu
这个作者很懒,什么都没留下…
展开
-
Leetcode Candy
题目:http://oj.leetcode.com/problems/candy/ 这道题很多人做了很长时间,从通过率也可以看出来。我的第一想法是从前往后遍历,如果i+1的rating大于i,则i+1的candy等于i的candy+1;如果小于,则从i开始往前遍历,直到处理完所有rating大且candy小于等于的情况,然后继续这个过程。这个思路代码实现起来稍微有点麻烦,而且时间复杂度是O(n...2013-10-04 11:10:35 · 150 阅读 · 0 评论 -
Leetcode Gas Station
题目:http://oj.leetcode.com/problems/gas-station/ 直观的想法就是枚举每个index,判断从该index开始是否能完成旅行,时间复杂度为O(n平方),代码如下: public class Solution { public int canCompleteCircuit(int[] gas, int[] cost) { ...2013-10-04 11:25:24 · 121 阅读 · 0 评论 -
Leetcode Generate Parentheses
题目:http://oj.leetcode.com/problems/generate-parentheses/ Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solutio...2013-10-07 16:15:26 · 111 阅读 · 0 评论