随笔分类 -  Algorithm

上一页 1 ··· 6 7 8 9 10 11 12 13 14 ··· 16 下一页
classic algorithm, problem
摘要:class Solution {public: int firstMissingPositive(int A[], int n) { if (A == NULL || n bits(len, false); for (int i=0; i n) continue;... 阅读全文
posted @ 2014-07-21 21:09 卖程序的小歪 阅读(164) 评论(0) 推荐(0)
摘要:class Solution {private: const static char* pattern[]; const static char* roman[]; unordered_map a2i;public: int romanToInt(string s) { ... 阅读全文
posted @ 2014-07-20 20:32 卖程序的小歪 阅读(124) 评论(0) 推荐(0)
摘要:class Solution {public: int trap(int A[], int n) { if (n peaks; vector peaks_tmp; int last_idx = 0; bool increasing = ... 阅读全文
posted @ 2014-07-20 17:27 卖程序的小歪 阅读(234) 评论(0) 推荐(0)
摘要:class Solution {public: vector > subsetsWithDup(vector &S) { int len = S.size(); vector > res; vector subset; if (len ... 阅读全文
posted @ 2014-07-19 09:03 卖程序的小歪 阅读(150) 评论(0) 推荐(0)
摘要:You are given annxn2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?class Solution {pub... 阅读全文
posted @ 2014-07-19 00:52 卖程序的小歪 阅读(161) 评论(0) 推荐(0)
摘要:class Solution {public: bool isPalindrome(int x) { if (x =0; i--) { int a = n / tens; int b = n % 10; n = n... 阅读全文
posted @ 2014-07-18 23:38 卖程序的小歪 阅读(233) 评论(0) 推荐(0)
摘要:class Solution {public: vector generateParenthesis(int n) { string str; vector res; dfs(n, 0, 0, str, res); return res;... 阅读全文
posted @ 2014-07-18 18:46 卖程序的小歪 阅读(163) 评论(0) 推荐(0)
摘要:class Solution {public: int maxSubArray(int A[], int n) { int cur_sum = 0; int max_sum = INT_MIN; for (int i=0; i max_... 阅读全文
posted @ 2014-07-18 18:40 卖程序的小歪 阅读(148) 评论(0) 推荐(0)
摘要:class Solution {public: void setZeroes(vector > &matrix) { int rows = matrix.size(); int cols = matrix[0].size(); bool... 阅读全文
posted @ 2014-07-18 15:52 卖程序的小歪 阅读(143) 评论(0) 推荐(0)
摘要:class Solution {public: ListNode *removeNthFromEnd(ListNode *head, int n) { if (head == NULL) return NULL; ListNode* pre = NULL; ... 阅读全文
posted @ 2014-07-18 14:36 卖程序的小歪 阅读(168) 评论(0) 推荐(0)
摘要:class Solution {private: int queen_num; int total;public: int totalNQueens(int n) { queen_num = n; total = 0; vector h(n... 阅读全文
posted @ 2014-07-17 19:53 卖程序的小歪 阅读(166) 评论(0) 推荐(0)
摘要:class Solution {public: void sortColors(int A[], int n) { int cnt[3] = {0}; for (int i = 0; i 0) start += cnt[i-1]; for (... 阅读全文
posted @ 2014-07-17 19:43 卖程序的小歪 阅读(146) 评论(0) 推荐(0)
摘要:class Solution {private: vector sum; vector step; set can;public: int jump(int A[], int n) { step.clear(), sum.clear(), can.clear()... 阅读全文
posted @ 2014-07-17 16:08 卖程序的小歪 阅读(203) 评论(0) 推荐(0)
摘要:class Solution {public: bool canJump(int A[], int n) { if (A == NULL || n sum(n, 0); int jump = A[n-1]; for (int i=n-... 阅读全文
posted @ 2014-07-16 16:38 卖程序的小歪 阅读(242) 评论(0) 推荐(0)
摘要:class Solution {private: int queen_num; vector > res;public: vector > solveNQueens(int n) { res.clear(); queen_num = n; ... 阅读全文
posted @ 2014-07-16 10:13 卖程序的小歪 阅读(158) 评论(0) 推荐(0)
摘要:class Solution {public: string countAndSay(int n) { vector num; num2digit(1, num); vector tmp; for (int i = 1; i &digit... 阅读全文
posted @ 2014-07-16 09:12 卖程序的小歪 阅读(156) 评论(0) 推荐(0)
摘要:class Solution {public: TreeNode *buildTree(vector &inorder, vector &postorder) { int ilen = inorder.size(); int plen = postorder.siz... 阅读全文
posted @ 2014-07-15 18:13 卖程序的小歪 阅读(184) 评论(0) 推荐(0)
摘要:class Solution {public: TreeNode *buildTree(vector &preorder, vector &inorder) { int plen = preorder.size(); int ilen = inorder.size(... 阅读全文
posted @ 2014-07-15 16:25 卖程序的小歪 阅读(144) 评论(0) 推荐(0)
摘要:/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; *... 阅读全文
posted @ 2014-07-15 10:38 卖程序的小歪 阅读(157) 评论(0) 推荐(0)
摘要:/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(... 阅读全文
posted @ 2014-07-15 10:11 卖程序的小歪 阅读(132) 评论(0) 推荐(0)

上一页 1 ··· 6 7 8 9 10 11 12 13 14 ··· 16 下一页