随笔分类 -  Algorithm

classic algorithm, problem
摘要:class Solution {public: bool isScramble(string s1, string s2) { int len = s1.length(); if (len == 1 && s1[0] == s2[0]) return true; ... 阅读全文
posted @ 2014-05-15 15:32 卖程序的小歪 阅读(171) 评论(0) 推荐(0)
摘要:class Solution {public: bool search(int A[], int n, int target) { if (n A[mid]) { right = mid; sep = A[mid]; ... 阅读全文
posted @ 2014-05-15 00:24 卖程序的小歪 阅读(164) 评论(0) 推荐(0)
摘要:class Solution {public: int canCompleteCircuit(vector &gas, vector &cost) { int len = gas.size(); if (len diff(len, 0); for (... 阅读全文
posted @ 2014-05-14 21:22 卖程序的小歪 阅读(257) 评论(0) 推荐(0)
摘要:class Solution {public: ListNode *insertionSortList(ListNode *head) { if (head == NULL) return NULL; ListNode* sorted_head = head; ... 阅读全文
posted @ 2014-05-10 17:26 卖程序的小歪 阅读(185) 评论(0) 推荐(0)
摘要:>Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.class Solution {public: int m... 阅读全文
posted @ 2014-05-10 15:20 卖程序的小歪 阅读(220) 评论(0) 推荐(0)
摘要:好久没写动态规划,中午听到学长们讨论的一道题,就是给出一组硬币面额,和一个目标数值,求有几种找零方式(想半天没想清楚)#include #include using namespace std;int count(int* s, int m, int n) { if (n == 0) retu... 阅读全文
posted @ 2014-05-08 23:48 卖程序的小歪 阅读(233) 评论(0) 推荐(0)
摘要:class Solution{ public: int maxArea(vector& height) { int len = height.size(), low = 0, high = len -1 ; int maxArea = 0; ... 阅读全文
posted @ 2014-05-08 09:56 卖程序的小歪 阅读(158) 评论(0) 推荐(0)
摘要:class Solution {private: vector result;public: vector wordBreak(string s, unordered_set &dict) { vector > dp; result.clear(); ... 阅读全文
posted @ 2014-05-07 21:26 卖程序的小歪 阅读(278) 评论(0) 推荐(0)
摘要:class Solution {private: int* memo;public: bool wordBreak(string s, unordered_set &dict) { memo = new int[s.length() + 1]; for (in... 阅读全文
posted @ 2014-05-06 16:12 卖程序的小歪 阅读(134) 评论(0) 推荐(0)
摘要:int sunday(string str, string pattern) { int str_len = str.length(); int pat_len = pattern.length(); int char_pos[256]; for (int i = 0... 阅读全文
posted @ 2014-05-06 15:27 卖程序的小歪 阅读(195) 评论(0) 推荐(0)
摘要:```cppclass Solution {public: void connect(TreeLinkNode *root) { if (root == NULL) return; queue que; que.push(root); i... 阅读全文
posted @ 2014-05-06 09:51 卖程序的小歪 阅读(154) 评论(0) 推荐(0)
摘要:Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-nega... 阅读全文
posted @ 2014-04-25 15:44 卖程序的小歪 阅读(169) 评论(0) 推荐(0)
摘要:class Solution {private: vector > nodes;public: vector > levelOrderBottom(TreeNode *root) { nodes.clear(); dfs(root, 0); re... 阅读全文
posted @ 2014-04-25 14:36 卖程序的小歪 阅读(129) 评论(0) 推荐(0)
摘要:class Solution {private: vector > nodes;public: vector > levelOrder(TreeNode *root) { nodes.clear(); dfs(root, 0); return n... 阅读全文
posted @ 2014-04-25 14:12 卖程序的小歪 阅读(232) 评论(0) 推荐(0)
摘要:class Solution {public: int search(int A[], int n, int target) { if (n last) { left = mid; } else { ... 阅读全文
posted @ 2014-04-23 22:50 卖程序的小歪 阅读(157) 评论(0) 推荐(0)
摘要:class Solution {private: vector > result;public: vector > pathSum(TreeNode *root, int sum) { result.clear(); vector path; d... 阅读全文
posted @ 2014-04-23 22:05 卖程序的小歪 阅读(175) 评论(0) 推荐(0)
摘要:class Solution {public: int singleNumber(int A[], int n) { sort(A, A+n); int last = A[0]; int time = 1; for (int i=1; i... 阅读全文
posted @ 2014-04-22 22:18 卖程序的小歪 阅读(144) 评论(0) 推荐(0)
摘要:class Solution {public: int singleNumber(int A[], int n) { int tmp = A[0]; for (int i=1; i<n; i++) { tmp ^= A[i]; }... 阅读全文
posted @ 2014-04-22 21:55 卖程序的小歪 阅读(164) 评论(0) 推荐(0)
摘要:class Solution {public: void connect(TreeLinkNode *root) { dfs(root, NULL); } void dfs(TreeLinkNode* root, TreeLinkNode* counter_p... 阅读全文
posted @ 2014-04-22 21:45 卖程序的小歪 阅读(211) 评论(0) 推荐(0)
摘要:class Solution {private: vector > result;public: vector > permute(vector &num) { result.clear(); dfs(num, 0); return result... 阅读全文
posted @ 2014-04-22 00:05 卖程序的小歪 阅读(114) 评论(0) 推荐(0)