摘要:class Solution {public: int minPathSum(vector > &grid) { // IMPORTANT: Please reset any member data you declared, as // the same Solution instance will be reused for each test case. if (grid.size()sums[j-1]) sums[j]=sums[j-1]+grid[i][j-1]; el...                    阅读全文
                
            leetcode - Linked List Cycle
2013-10-31 14:59 by 张汉生, 156 阅读, 0 推荐, 收藏,
摘要:1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * ListNode(int x) : val(x), next(NULL) {} 7 * }; 8 */ 9 class Solution {10 public:11 bool hasCycle(ListNode *head) {12 // IMPORTANT: Please reset any member data you ...                    阅读全文
                
            leetcode - Triangle
2013-10-27 15:24 by 张汉生, 155 阅读, 0 推荐, 收藏,
摘要:1 class Solution { 2 public: 3 int minimumTotal(vector > &triangle) { 4 // Note: The Solution object is instantiated only once and is reused by each test case. 5 const int maxN = 1000000000; 6 int n = triangle.size(); 7 if (n rlt(n,0);10 rlt[0] = triangle...                    阅读全文
                
            leetcode - Search a 2D Matrix
2013-10-27 15:08 by 张汉生, 136 阅读, 0 推荐, 收藏,
摘要:1 class Solution { 2 public: 3 bool searchMatrix(vector > &matrix, int target) { 4 // IMPORTANT: Please reset any member data you declared, as 5 // the same Solution instance will be reused for each test case. 6 int m =matrix.size(); 7 if (m=target)16 ...                    阅读全文
                
            leetcode - Pascal's Triangle II
2013-10-27 14:48 by 张汉生, 181 阅读, 0 推荐, 收藏,
摘要:1 class Solution { 2 public: 3 vector getRow(int rowIndex) { 4 // Note: The Solution object is instantiated only once and is reused by each test case. 5 vector rlt(rowIndex+1, 1); 6 for (int i=0; i<=rowIndex; i++){ 7 int last = 1; 8 int cur = 1; 9...                    阅读全文
                
            leetcode - Spiral Matrix II
2013-10-27 12:11 by 张汉生, 139 阅读, 0 推荐, 收藏,
摘要:1 class Solution { 2 public: 3 vector > generateMatrix(int n) { 4 // Note: The Solution object is instantiated only once and is reused by each test case. 5 vector > matrix; 6 if (n vi;13 for (j=0; jflag[j+1])21 break;22 int start =...                    阅读全文
                
            leetcode - Spiral Matrix
2013-10-27 12:04 by 张汉生, 144 阅读, 0 推荐, 收藏,
摘要:1 class Solution { 2 public: 3 vector spiralOrder(vector > &matrix) { 4 // Note: The Solution object is instantiated only once and is reused by each test case. 5 vector rlt; 6 int m =matrix.size(); 7 if (mflag[j+1])18 break;19 int star...                    阅读全文
                
            leetcode - Permutations
2013-10-27 10:21 by 张汉生, 164 阅读, 0 推荐, 收藏,
摘要:1 class Solution { 2 public: 3 vector > permute(vector &num) { 4 // Note: The Solution object is instantiated only once and is reused by each test case. 5 sort(num.begin(),num.end()); 6 vector> rlt; 7 rlt.push_back(num); 8 int n = num.size(); 9 wh...                    阅读全文
                
            leetcode - Pascal's Triangle
2013-10-27 09:52 by 张汉生, 154 阅读, 0 推荐, 收藏,
摘要:1 class Solution { 2 public: 3 vector > generate(int numRows) { 4 // Note: The Solution object is instantiated only once and is reused by each test case. 5 vector> rlt; 6 if (numRows tmp; 9 tmp.push_back(1);10 rlt.push_back(tmp);11 for (int i=1; i...                    阅读全文
                
            leetcode - Swap Nodes in Pairs
2013-10-23 19:44 by 张汉生, 128 阅读, 0 推荐, 收藏,
摘要:1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * ListNode(int x) : val(x), next(NULL) {} 7 * }; 8 */ 9 class Solution {10 public:11 ListNode *swapPairs(ListNode *head) {12 // Note: The Solution object is instantia...                    阅读全文
                
            
                    
                
浙公网安备 33010602011771号