- 博客(51)
- 资源 (6)
- 收藏
- 关注
原创 leetcode 日经贴,Cpp code -The Skyline Problem
The Skyline Problemclass Solution {public: vector> getSkyline(vector>& buildings) { vector > vertical_lines; for (int i = 0; i < buildings.size(); ++i) { vector &b
2015-05-26 11:42:43 471
原创 leetcode 日经贴,Cpp code -Contains Duplicate
Contains Duplicateclass Solution {public: bool containsDuplicate(vector& nums) { unordered_set us; for (int i = 0; i < nums.size(); ++i) { if (us.find(nums[i]) !=
2015-05-26 11:07:47 319
原创 leetcode 日经贴,Cpp code -Minimum Window Substring
Minimum Window Substringclass Solution {public: string minWindow(string s, string t) { vector count(256); int st = -1, ed = s.length(), distinct = 0; for (int i = 0; i
2015-05-24 17:21:35 500
原创 leetcode 日经贴,Cpp code -Combination Sum III
Combination Sum IIIclass Solution {public: void dfs(int current, int sum, vector &cans, vector >&ans, int k) { if (sum == 0 && cans.size() == k) { ans.push_back(cans);
2015-05-24 14:14:37 450 1
原创 leetcode 日经贴,Cpp code -Shortest Palindrome
Shortest Palindromeclass Solution {public: bool isPalindrome(const string &s, int st, int ed) { while (st < ed) { if (s[st] != s[ed]) { return false;
2015-05-24 14:04:33 306
原创 leetcode 日经贴,Cpp code -House Robber II
House Robber IIclass Solution {public: int roblinear(int *ary, int n) { int a = 0, b = 0; for (int i = 0; i < n; ++i) { int c = max(a, b); a = b + ary[
2015-05-20 10:26:12 434
原创 leetcode 日经贴,Cpp code -Add and Search Word - Data structure design
Add and Search Word - Data structure designstruct Trie { bool end; Trie *next[26]; Trie() { end = false; memset(next, 0, sizeof(next)); }};class WordDictionary {
2015-05-19 13:00:59 429
转载 Longest common subsequence
https://www.ics.uci.edu/~eppstein/161/960229.htmlICS 161: Design and Analysis of AlgorithmsLecture notes for February 29, 1996Longest Common SubsequencesIn this lecture we examine
2015-05-18 10:39:53 1810
原创 mod_python
install:./configure --with-apxs=/Applications/XAMPP/bin/apxs --with-flex=/Applications/XAMPP/bin/flexmakesudo make install
2015-05-14 17:11:35 472
原创 leetcode 日经贴,Cpp code -Multiply Strings
Multiply Stringsclass Solution {public: string multiplyPositive(string num1, string num2) { reverse(num1.begin(), num1.end()); reverse(num2.begin(), num2.end()); int n
2015-05-14 11:19:25 281
原创 leetcode 日经贴,Cpp code -First Missing Positive
First Missing Positiveclass Solution {public: int firstMissingPositive(vector& nums) { int n = nums.size(); for (int i = 0; i < n; ++i) { int v = nums[i];
2015-05-14 11:00:08 285
原创 leetcode 日经贴,Cpp code -Combination Sum
Combination Sumclass Solution {public: void dfs(const vector &candidates, vector > ¤t, int pos, int target, vector > &ans) { if (target == 0) { vector currentans;
2015-05-14 10:48:45 303
原创 leetcode 日经贴,Cpp code -Course Schedule II
Course Schedule IIclass Solution {public: vector findOrder(int numCourses, vector>& prerequisites) { vector inorder; vector > edge; inorder.resize(numCourses);
2015-05-14 10:38:44 315
原创 Some material form web for Understanding javascript
http://dmitrysoshnikov.com/ecmascript/javascript-the-core/JavaScript Module Pattern: In-Depth
2015-05-13 11:37:35 339
原创 leetcode 日经贴,Cpp code -Trapping Rain Water
Trapping Rain Waterclass Solution {public: int trap(vector& height) { int n = height.size(); stack >st; int maxh = 0, omit = 0; for (int i = 0; i < n; ++i) {
2015-05-12 17:21:18 345
原创 leetcode 日经贴,Cpp code -Count and Say
Count and Sayclass Solution {public: string a2i(int n) { if (!n) { return "0"; } string s; while (n) { s = char(n%10 + '0') + s;
2015-05-12 16:36:07 313
原创 leetcode 日经贴,Cpp code -Minimum Size Subarray Sum
Minimum Size Subarray Sumclass Solution {public: int minSubArrayLen(int s, vector& nums) { int n = nums.size(); int minlen = 0, p1 = 0, p2 = 0, sum = 0; while (p2 < n)
2015-05-12 16:29:50 380
原创 Programming Interview Questions 111: Design url shorten system
System Design for Big Data [tinyurl]How to code a URL shortener?
2015-05-11 18:31:59 408
原创 leetcode 日经贴,Cpp code -Sudoku Solver
Sudoku Solverclass Solution {public: int getValidMove(const vector >&board, int r, int c) { assert(board[r][c] == '.'); int s = 0; //row for (int j = 0; j < 9;
2015-05-11 17:17:46 386
原创 leetcode 日经贴,Cpp code -Valid Sudoku
Valid Sudokuclass Solution {public: bool validcell(vector &vi) { sort(vi.begin(), vi.end()); for (int i = 1; i < vi.size(); ++i) { if (vi[i] == vi[i - 1]) {
2015-05-11 16:55:22 294
原创 leetcode 日经贴,Cpp code -Search Insert Position
Search Insert Positionclass Solution {public: int searchInsert(vector& nums, int target) { int low = 0, high = nums.size(), mid = 0; while (low < high) { mid = (lo
2015-05-11 16:43:42 369
原创 Programming Interview Questions 9: Convert Array
Programming Interview Questions 9: Convert ArrayGiven an array [a1, a2, ..., aN, b1, b2, ..., bN, c1, c2, ..., cN] convert it to [a1, b1, c1, a2, b2, c2, ..., aN, bN, cN] in-place using const
2015-05-08 16:44:46 382
原创 Programming Interview Questions 26: Trim Binary Search Tree
My Facebook interview question. Feb of 2015Programming Interview Questions 26: Trim Binary Search TreeO(n) complexityvoid remove(TreeNode *r) { if (!r) return; remove(r->left); remove(
2015-05-08 13:32:16 348
原创 leetcode 日经贴,Cpp code -Gray Code
Gray Codeclass Solution {public: vector grayCode(int n) { vector vi; vi.push_back(0); for (int i = 0; i < n; ++i) { int m = vi.size(); while (m
2015-05-08 11:00:00 308
原创 leetcode 日经贴,Cpp code -Subsets II
Subsets IIclass Solution {public: void gen(const vector &nums, int p, vector >&sets, vector &set) { int n = nums.size(); if (n == p) { sets.push_back(set);
2015-05-08 10:56:59 354
原创 leetcode 日经贴,Cpp code -Restore IP Addresses
Restore IP Addressesclass Solution {public: void gen(const string &s, int pos, int k, vector &ips, string &curstring) { int n = s.length(); if (k == 4) { if (n ==
2015-05-08 10:49:12 344
原创 leetcode 日经贴,Cpp code -Implement Trie (Prefix Tree)
Implement Trie (Prefix Tree)class TrieNode {private: TrieNode *next[26]; bool ed;public: // Initialize your data structure here. TrieNode() { memset(next, 0, sizeof(TrieN
2015-05-08 10:36:26 398
原创 interview question
http://www.ardendertat.com/2012/01/09/programming-interview-questions/http://www.ardendertat.com/2011/05/30/how-to-implement-a-search-engine-part-1-create-index/
2015-05-07 14:19:31 358
原创 leetcode 日经贴,Cpp code -Course Schedule
Course Scheduleclass Solution {public: bool canFinish(int numCourses, vector>& prerequisites) { vector inorder(numCourses); vector edge[numCourses]; for (int i = 0; i
2015-05-07 10:57:19 480 2
原创 leetcode 日经贴,Cpp code -Convert Sorted Array to Binary Search Tree
Convert Sorted Array to Binary Search Tree/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val
2015-05-07 10:50:32 296
原创 leetcode 日经贴,Cpp code -Construct Binary Tree from Inorder and Postorder Traversal
Construct Binary Tree from Inorder and Postorder Traversal/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * Tre
2015-05-07 10:45:03 301
原创 leetcode 日经贴,Cpp code -Construct Binary Tree from Preorder and Inorder Traversal
Construct Binary Tree from Preorder and Inorder Traversal/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * Tree
2015-05-07 10:39:27 404
原创 leetcode 日经贴,Cpp code -Merge Sorted Array
Merge Sorted Arrayclass Solution {public: void merge(vector& nums1, int m, vector& nums2, int n) { nums1.resize(n + m); int i = m - 1, j = n - 1, k = n + m - 1; while
2015-05-07 10:30:28 352
原创 leetcode 日经贴,Cpp code -Permutation Sequence
Permutation Sequenceclass Solution {public: string getPermutation(int n, int k) { string s = ""; vector fact; fact.resize(n + 1); fact[0] = 1; for (int
2015-05-06 15:01:16 322
原创 leetcode 日经贴,Cpp code -Permutations
Permutationsclass Solution {public: bool next_permutation(vector &nums) { int n = nums.size(); if (n <= 1) { return false; } int ed = n - 1;
2015-05-06 14:44:10 285
原创 leetcode 日经贴,Cpp code -Permutations II
Permutations IIclass Solution {public: bool next_permutation(vector &nums) { int n = nums.size(); if (n <= 1) { return false; } int ed = n - 1;
2015-05-06 14:43:52 294
原创 leetcode 日经贴,Cpp code -Plus One
Plus Oneclass Solution {public: vector plusOne(vector& digits) { vector ret = digits; reverse(ret.begin(), ret.end()); ret[0] += 1; int carry = 0; for
2015-05-06 12:51:45 277
原创 leetcode 日经贴,Cpp code -Pow(x, n)
Pow(x, n)class Solution {public: double myPow(double x, int n) { if (n == 0) { return 1.0; } bool neg = n < 0; long long ln = n; if (ln < 0
2015-05-06 12:48:39 263
原创 leetcode 日经贴,Cpp code -Binary Tree Level Order Traversal II
Binary Tree Level Order Traversal II/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), l
2015-05-05 18:56:21 323
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人