- 博客(25)
- 资源 (2)
- 收藏
- 关注
转载 Largest Number
class Solution {public: string largestNumber(vector& nums) { string m_res = ""; if (nums.size() < 1) return m_res; sort(nums.begin(),nums.end(),compare);
2015-06-30 14:14:42 280
原创 Python 多线程分块读文件
这里参考了这篇文章 https://gist.github.com/friskfly/4412375 ,然后加上自己的理解和应用, 整理如下: # -*- coding: utf-8 -*-import os,timeimport threadingimport ConfigParserrlock = threading.RLock()curPosition = 0cl
2015-06-30 10:35:42 2807 3
原创 Binary Tree Preorder Traversal
/** * 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-06-24 16:48:33 463
原创 Evaluate Reverse Polish Notation
class Solution {public: int evalRPN(vector& tokens) { if(tokens.empty()) return 0; stack s; int res=0; const int n=tokens.size(); for(int
2015-06-24 16:37:05 234
原创 Intersection of Two Linked Lists
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode *ge
2015-06-24 16:06:34 257
转载 Minimum Window Substring
class Solution {public: string minWindow(string S, string T) { if (S.empty() || T.empty()) { return ""; } int count = T.size(); int require[128
2015-06-19 11:32:49 309
转载 Anagrams
class Solution {public: vector anagrams(vector& strs) { map m; vector res; if(strs.empty()) return res; const int n=strs.size();
2015-06-16 23:22:58 286
转载 Reverse Words in a String
class Solution {public: void reverseWords(string &s) { string res=""; int i=0; const int n=s.size(); while(true) { while(i<n && s[i]==' ')
2015-06-16 23:19:56 273
转载 Spiral Matrix
class Solution {public: vector spiralOrder(vector>& matrix) { vector res; if(matrix.empty()||matrix[0].empty()) return res; int m=matrix.
2015-06-16 11:16:37 244
转载 Find Peak Element
class Solution {public: int findPeakElement(vector& nums) { int low=0; int high=nums.size()-1; while(low<high) { int mid=low+(high-low)/2;
2015-06-15 11:26:34 308
转载 Maximum Subarray
class Solution {public: int maxSubArray(vector& nums) { const int n=nums.size(); int maxSum=0; //每一段的最大值,局部最优 int result=INT_MIN; //全局最优 for(int i=0;i<
2015-06-09 12:53:13 237
原创 Search for a Range
class Solution {public: vector searchRange(vector& nums, int target) { const int n=nums.size(); vector res(2,-1); int start=0;int end=n-1; while(star
2015-06-09 12:52:03 303
转载 Reverse Nodes in k-Group
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode* re
2015-06-04 16:13:45 279
转载 Container With Most Water
class Solution {public: int maxArea(vector& height) { const int n=height.size(); int leftWall=height[0]; int rightWall=height[n-1]; int left=0; int ri
2015-06-04 15:42:01 238
原创 Search a 2D Matrix
class Solution {public: bool searchMatrix(vector>& matrix, int target) { const int m=matrix.size(); const int n=matrix[0].size(); int i=0; int j=n-1;
2015-06-04 15:06:37 224
原创 Remove Nth Node From End of List
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode* re
2015-06-04 14:57:31 312
转载 Max Points on a Line(转载,完全转载hackersun)
/** * Definition for a point. * struct Point { * int x; * int y; * Point() : x(0), y(0) {} * Point(int a, int b) : x(a), y(b) {} * }; */class Solution {public: int maxPoi
2015-06-03 11:21:14 229
转载 Reverse Linked List II
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode* re
2015-06-02 14:58:56 256
转载 Reverse Linked List
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode* re
2015-06-02 10:07:49 255
转载 Remove Duplicates from Sorted List II
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode* de
2015-06-02 09:47:06 555
转载 Search in Rotated Sorted Array
class Solution {public: int search(vector& nums, int target) { int low=0; int high=nums.size()-1; while(low<=high) { int mid=low+(high-low)/2;
2015-06-01 23:27:42 264
转载 Search in Rotated Sorted Array II
class Solution {public: bool search(vector& nums, int target) { int low=0; int high=nums.size()-1; while(low<=high) { int mid=low+(high-low)/2;
2015-06-01 23:27:14 294
原创 Remove Duplicates from Sorted Array II
class Solution {public: int removeDuplicates(vector& nums) { const int n=nums.size(); if(0==n) return 0; int temp=nums[0]; int length=0; f
2015-06-01 19:42:29 221
原创 Remove Duplicates from Sorted Array
class Solution {public: int removeDuplicates(vector& nums) { if(nums.empty()) return 0; const int n=nums.size(); int length=0; int temp=nums[0];
2015-06-01 16:41:14 239
转载 Maximum Subarray
class Solution {public: int maxSubArray(vector& nums) { const int n=nums.size(); int MaxSum=nums[0]; int curMax=nums[0]; for(int i=1;i<n;++i) {
2015-06-01 16:13:50 213
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人