`
文章列表
参考:http://pthread.blog.163.com/blog/static/169308178201210112045787/   Most textbooks mention that binary tree can be traversed using recursion or , using stack without recursion. The recursive procedure is simple to write, and the stack version use extra space.  There's also a very well designe ...
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode *deleteDuplicates(ListNode *head) { if(!head) return NULL; if(!head->ne ...
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode *deleteDuplicates(ListNode *head) { if(!head) return NULL; if(!head->nex ...
Question:    input :     n   output:    A random permutation of [0 ..  n-1]   ie:   input: 5 output: 0 3 2 4 1    // Type your C++ code and click the "Run Code" button! // Your code output will be shown on the left. // Click on the "Show input" button to enter input ...
Question:   Given a list, rotate the list to the right by k places, where k is non-negative. For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL.   /** * Definition for singly-linked list. * struct ListNode { *
question:   Say you have an array for which the ith element is the price of a given stock on day i.   If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), design an algorithm to find the maximum profit.   class Solution { public: i ...
class Solution { public: int longestConsecutive(vector<int> &num) { int n = num.size(); if(n <= 0) return 0; if(n == 1) return 1; sort(num.begin(), num.end()); int maxAll = 1; int maxLast = 1; ...
#define TEMP_FLAG 'Z' #define O_FLAG 'O' #define X_FLAG 'X' class Solution { public: void solve(vector<vector<char>> &board) { int m = board.size(); if(m <= 0) return; // deal with the border element for(int i = 0; ...
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class Solution { public: int sumNumbers(TreeNode *root) { vector<vector<int>&g ...
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class Solution { public: bool hasPathSum(TreeNode *root, int sum) { if(!root) return fa ...
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class Solution { public: vector<vector<int> > pathSum(TreeNode *root, int sum) { ...
// Type your C++ code and click the "Run Code" button! // Your code output will be shown on the left. // Click on the "Show input" button to enter input data to be read (from stdin). #include <iostream> using namespace std; struct ListNode { int val; Lis ...
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ // rule in result vector during iteration: // single path: 0; ----> v0 // cross path: 1; ...
// Type your C++ code and click the "Run Code" button! // Your code output will be shown on the left. // Click on the "Show input" button to enter input data to be read (from stdin). #include <iostream> using namespace std; class Solution { public: int rever ...
// Type your C++ code and click the "Run Code" button! // Your code output will be shown on the left. // Click on the "Show input" button to enter input data to be read (from stdin). #include <iostream> using namespace std; typedef struct GNode { int val; ...
Global site tag (gtag.js) - Google Analytics