
leetcode
wjk20120522
这个作者很懒,什么都没留下…
展开
-
[leetcode]Climbing Stairs
class Solution {public: int climbStairs(int n) { int firster = 1; int seconder = 2; if(1 == n) { return 1; } else if(2 == n) { return 2; } int i,resul原创 2014-04-10 16:28:38 · 734 阅读 · 0 评论 -
[leetcode]String to Integer (atoi)
题目:https://oj.leetcode.com/problems/string-to-integer-atoi/代码:class Solution {public: int atoi(const char *str) { if (str == NULL) return 0; long long int res = 0, i; bool neg原创 2014-11-30 14:06:24 · 724 阅读 · 0 评论 -
[leetcode]ZigZag Conversion
题目: https://oj.leetcode.com/problems/zigzag-conversion/ https://oj.leetcode.com/problems/zigzag-conversion/需要找到每行各种字符对应在源字符的位置,即找出两者之间的规律。这题就比较好解了。代码:class Solution {public: string原创 2014-11-30 14:10:36 · 858 阅读 · 0 评论 -
[leetcode]Search a 2D Matrix
题目: https://oj.leetcode.com/problems/search-a-2d-matrix/思路: 从二维数组的左上角原创 2014-09-30 18:15:48 · 750 阅读 · 0 评论 -
[leetcode]Sort Colors
题目地址: https://oj.leetcode.com/problems/sort-colors/原创 2014-09-30 15:13:30 · 802 阅读 · 0 评论 -
[leetcode]Populating Next Right Pointers in Each Node
参考别人写的代码, 代码很赞原创 2014-09-30 09:42:47 · 771 阅读 · 0 评论 -
[leetcode]Insertion Sort List
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode *in原创 2014-04-11 14:56:40 · 801 阅读 · 0 评论 -
[leetcod]Evaluate Reverse Polish Notation
class Solution {public: int evalRPN(vector &tokens) { vector::iterator it; vector temp; int result = 0; if( 0 == tokens.size() ) { return 0; } while(true) {原创 2014-04-11 22:23:41 · 797 阅读 · 0 评论 -
[leetcode]Merge Sorted Array
class Solution {public: void merge(int A[], int m, int B[], int n) { // use STL function copy( B, B + n, A + m); sort(A, A + m + n); /** another concrete method *********原创 2014-04-11 13:17:16 · 799 阅读 · 0 评论 -
[leetcode]Binary Tree Preorder Traversal
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Soluti原创 2014-04-10 16:44:32 · 767 阅读 · 0 评论 -
[leetcode] Binary Tree Level Order Traversal
#include #include #include #include #include #include using namespace std;struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) {}}原创 2014-04-10 16:26:27 · 849 阅读 · 0 评论 -
[leetcode]Binary Tree Postorder Traversal
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Soluti原创 2014-04-10 16:47:42 · 727 阅读 · 0 评论 -
[leetcode]Edit Distance
class Solution {public: int minDistance(string word1, string word2) { int len1 = word1.length(), len2 = word2.length(); if(len1 == 0) return len2; //if word1 is empty if(len2 == 0)原创 2014-04-11 11:02:23 · 661 阅读 · 0 评论 -
[leetcode]4Sum
题目: https://oj.leetcode.com/problems/4sum/代码:对于这类问题首先需要将数组进行整体排序。然后比较某两个数是否存在和target-这两个数和 相等的两个数。值得注意的是,要考虑到重复的情况,所以需要用set之类作区分。class Solution {public: vector > fourSum(vector &n原创 2014-11-30 14:14:42 · 791 阅读 · 0 评论