随笔分类 - Algorithm
classic algorithm, problem
摘要:class Solution {public: vector restoreIpAddresses(string s) { vector ips; vector ip; dfs(s, 0, ip, ips); return ips; ...
阅读全文
摘要:class Solution {public: vector plusOne(vector &digits) { int carry = 1; int len = digits.size(); vector res; ...
阅读全文
摘要:class Solution {public: ListNode *reverseBetween(ListNode *head, int m, int n) { if (head == NULL || n 0) { pre = cur; ...
阅读全文
摘要:class Solution {public: vector > generate(int numRows) { vector > res; if (numRows row(1, 1); res.push_back(row); ...
阅读全文
摘要:class Solution {public: vector getRow(int rowIndex) { int half = (rowIndex + 1) / 2; int len = half * 2 + !(rowIndex & 0x1); ...
阅读全文
摘要:/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; *...
阅读全文
摘要:class Solution {private: vector > res;public: vector > combine(int n, int k) { res.clear(); vector path; dfs(1, n, k, path)...
阅读全文
摘要:class Solution {public: int minPathSum(vector > &grid) { int rows = grid.size(); if (rows pathsum(cols + 1, INT_MAX); pathsum...
阅读全文
摘要:class Solution {public: bool isPalindrome(string s) { int len = s.length(); //if (len -1 && !(b = check2lower(s[q])) ); i...
阅读全文
摘要:class Solution {public: int longestConsecutive(vector &num) { int len = num.size(); int max_cons = 0; int cur_cons = 0...
阅读全文
摘要:class Solution {public: int removeElement(int A[], int n, int elem) { if (A == NULL || n < 1) return 0; int rpos = 0, wpos = 0; ...
阅读全文
摘要:class Solution {public: int reverse(int x) { bool neg = x = 0; 8 while (x) { 9 int d = x % 10;10 if (positiv...
阅读全文
摘要:/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(...
阅读全文
摘要:/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(...
阅读全文
摘要:class Solution {public: int threeSumClosest(vector &num, int target) { int len = num.size(); if (len target) { q-...
阅读全文
摘要:/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; *...
阅读全文
摘要:class Solution {public: int maxProfit(vector &prices) { int len = prices.size(); if (len &prices) { int len = prices.size(); ...
阅读全文
摘要:/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(...
阅读全文
摘要:/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(...
阅读全文
摘要:/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; *...
阅读全文

浙公网安备 33010602011771号