随笔分类 -  LeetCode OJ

上一页 1 2 3

LeetCode---Merge Intervals
摘要:题目链接区间合并,贪心,需要注意边界情况,LeetCode的数据还是比较好的,这样才能写出健壮的程序。附上代码: 1 /** 2 * Definition for an interval. 3 * struct Interval { 4 * int start; 5 * in... 阅读全文

posted @ 2014-05-02 21:39 Stomach_ache 阅读(150) 评论(0) 推荐(0)

LeetCode---Triangle
摘要:题目链接很简单的递推,但是写代码的过程中,犯了一个严重的错误,就是我用unsigned int型变量>= 0 作为循环条件(而且是降序)的时候,出现了问题。附上代码: 1 class Solution { 2 public: 3 int minimumTotal(vector > &tria... 阅读全文

posted @ 2014-05-02 21:03 Stomach_ache 阅读(134) 评论(0) 推荐(0)

LeedCode OJ -- String to Integer (atoi)
摘要:点击打开题目链接题目意思就是自己实现一个atoi函数,也就是将字符串转换成int型。关于INT_MAX和INT_MIN, 只是在文件中定义的宏..分别是int型可以表示的最大值和最小值还有就是定义大整数常量的时候,会出现这种警告:warning: this decimal constant is u... 阅读全文

posted @ 2014-04-26 17:58 Stomach_ache 阅读(265) 评论(0) 推荐(0)

LeedCode OJ --- Binary Tree Inorder Traversal
摘要:点击打开题目链接今天只是写了递归的版本,因为还没想好怎么用迭代来实现,可以写的过程中,有一点是有疑问的,虽然我的代码可以AC。问题是:主调函数是可以使用子函数中返回的在子函数中定义的vector. 我认为在被调函数执行结束之后,其分配的空间是应该被释放的,所以在被调函数中定义的变量也是不可以被主调函... 阅读全文

posted @ 2014-04-26 00:26 Stomach_ache 阅读(155) 评论(0) 推荐(0)

LeetCode----Path Sum
摘要:Path Sum Total Accepted: 9765 Total Submissions: 32502 My SubmissionsGiven a binary tree and a sum, determine if the tree has a root-to-leaf path suc... 阅读全文

posted @ 2014-03-27 19:52 Stomach_ache 阅读(150) 评论(0) 推荐(0)

LeetCode OJ---Sqrt(x)
摘要:题目链接:http://oj.leetcode.com/problems/sqrtx/看题目就知道是水题一枚,做这个平台的题目还是没有习惯,毕竟这里的题目都是以面试为目的的,所以Coding的时候一定要谨慎.这里使用二分查找,二分虽然思路很简单,但是代码还是有几个地方值得注意的,比如 mid = l... 阅读全文

posted @ 2014-03-19 12:24 Stomach_ache 阅读(158) 评论(0) 推荐(0)

上一页 1 2 3

导航