- 博客(9)
- 资源 (4)
- 收藏
- 关注
原创 Implement Stack using Queues && Implement Queue using Stacks
Implement Stack using Queuesclass Stack {private: queueint> q;public: // Push element x onto stack. void push(int x) { queueint> t; while (!q.empty()) { t.p
2015-07-23 01:42:22 334
原创 Power of Two
class Solution {public: bool isPowerOfTwo(int n) { if (n < 1) return false; while (n > 2) { if (n % 2) return false; n = n/2; } return true
2015-07-23 01:03:22 314
原创 Maximum Gap
#1: sortO(nlogn)class Solution {public: int maximumGap(vectorint>& nums) { int n = nums.size(); if (n < 2) return 0; int res = 0; sort(nums.begin(), nums.end()
2015-07-21 14:44:16 268
原创 Summary Ranges
class Solution {public: string num2str(int num) { string res; int p = 0; long n = num; if (n < 0) { res.push_back('-'); p = 1;
2015-07-19 07:52:41 331
原创 Kth Smallest Element in a BST
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */clas
2015-07-17 03:04:45 295
原创 Delete Node in a Linked List
/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */void deleteNode(struct ListNode* node) { *node = *(node->next);}
2015-07-16 01:33:12 384
原创 Lowest Common Ancestor of a Binary Tree
BST:/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; *
2015-07-16 01:26:12 272
原创 Palindrome Linked List
#1 using stacktime: O(n); space O(n)/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */c
2015-07-14 15:34:25 357
原创 Rotate Array
class Solution {public: void rotate(vectorint>& nums, int k) { int n = nums.size(); if (k > n) k = k % n; if (n == k || k < 1) return; vectorint> temp(nums.begin(
2015-07-09 14:20:23 376
Cracking the Coding Interview
2013-01-17
Distributed and Cloud Computing
2013-01-17
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人