
LeetCode
seagullyoyo
for the load your god is with you whereever you go
展开
-
Two Sum
#include #include #include using namespace std;class Solution1 {public: vector twoSum(vector &numbers, int target) { vector v; for(int i = 0; i < numbers.size(); ++i) { for(int原创 2014-07-17 17:05:38 · 378 阅读 · 0 评论 -
Convert Sorted Array to Binary Search Tree
#include #include using namespace std;struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) {}};class Solution {public:原创 2014-07-29 11:10:24 · 424 阅读 · 0 评论 -
Path Sum II
#include #include #include using namespace std;struct TreeNode { int val; TreeNode *left, *right; TreeNode(int x) : val(x), left(NULL), right(NULL) {}};vector > v;class Solution {public:原创 2014-07-28 20:22:05 · 345 阅读 · 0 评论 -
Populating Next Right Pointers in Each Node I II 均AC
感觉写的真啰嗦#include #include #include using namespace std;struct TreeLinkNode { int val; TreeLinkNode *left, *right, *next; TreeLinkNode(int x) : val(x), left(NULL), right(NULL), next(NULL) {}原创 2014-07-28 19:17:02 · 378 阅读 · 0 评论 -
Path Sum
深搜 递归#include using namespace std;struct TreeNode { int val; TreeNode *left, *right; TreeNode(int x) : val(x), left(NULL), right(NULL) {}};class Solution {public: bool hasPathSum(Tree原创 2014-07-28 19:39:45 · 457 阅读 · 0 评论 -
Balanced Binary Tree
仔细,仔细,仔细!#include #include #include using namespace std;struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) {}};cla原创 2014-07-29 10:36:36 · 382 阅读 · 0 评论 -
Pascal's Triangle
#include #include using namespace std;class Solution {public: vector > generate(int numRows) { vector > v; for(int i = 0; i < numRows; ++i) { if(i == 0) { ve原创 2014-07-28 14:35:13 · 381 阅读 · 0 评论 -
Best Time to Buy and Sell Stock III
本解法启发自http://blog.youkuaiyun.com/pickless/article/details/12034365原创 2014-07-28 13:45:50 · 398 阅读 · 0 评论 -
Best Time to Buy and Sell Stock 2
没有想出来,网上搜的答案。原创 2014-07-28 10:08:50 · 431 阅读 · 0 评论 -
Pascal's Triangle 2
#include #include using namespace std;class Solution {public: vector getRow(int rowIndex) { int *t = new int[rowIndex + 1]; memset(t, 0, sizeof(int) * rowIndex); t[0] = 1; for(原创 2014-07-28 15:08:36 · 382 阅读 · 0 评论 -
Binary Tree Preorder Traversal
非递归用栈实现先序遍历原创 2014-07-19 15:37:11 · 408 阅读 · 0 评论 -
Insertion Sort List(自我感觉写的挺好)
果然脑袋混沌的时候就应该去放松一下,昨天下午xiang原创 2014-07-19 09:46:17 · 456 阅读 · 0 评论 -
SortList
好题目,总结一下。1、要求时间效率O(NlogN),就原创 2014-07-18 16:22:49 · 496 阅读 · 0 评论 -
Binary Tree Postorder Traversal
#include #include using namespace std;struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) {}};class Solution {public:原创 2014-07-19 13:14:34 · 407 阅读 · 0 评论 -
Reverse Words in a String
快特么气成傻逼了才AC#include #include using namespace std;stack st;class Solution {public: void reverseWords(string &s) { int i = s.find_first_not_of(" "); if(i > s.size()) { s = ""; r原创 2014-07-17 20:24:37 · 510 阅读 · 0 评论 -
Evaluate Reverse Polish Notation
stack st;class Solution {public: int evalRPN(vector &tokens) { for(int i = 0; i != tokens.size(); ++i) { if(tokens[i][0] >= '0' && tokens[i][0] = '0' && tokens[i][1] <= '9') { s原创 2014-07-17 20:57:06 · 327 阅读 · 0 评论 -
Convert Sorted List to Binary Search Tree
链表实现的话,快慢指针原创 2014-07-29 16:10:57 · 442 阅读 · 0 评论