leetcode
zhangmengjlu
这个作者很懒,什么都没留下…
展开
-
【leetcode】Valid Number
class Solution {public: bool isNumber(const char *s) { // Note: The Solution object is instantiated only once and is reused by each test case. //有限自动机,和处理图书章节前的“第1.1章”的方法类似原创 2013-10-29 23:20:42 · 567 阅读 · 0 评论 -
【leetcode】Reverse Integer
class Solution {public: int reverse(int x) { // Note: The Solution object is instantiated only once and is reused by each test case. if(x==0) return 0;//x==0 int原创 2013-10-08 20:53:26 · 400 阅读 · 0 评论 -
【leetcode】Search in Rotated Sorted Array II
class Solution {public: bool search(int A[], int n, int target) { // Note: The Solution object is instantiated only once and is reused by each test case. int sta=0,end=n-1;原创 2013-10-08 13:32:14 · 382 阅读 · 0 评论 -
【leetcode】Binary Tree Level Order Traversal II
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Soluti原创 2013-10-07 15:11:37 · 372 阅读 · 0 评论 -
【leetcode】3Sum Closest
class Solution {public: int threeSumClosest(vector &num, int target) { // Note: The Solution object is instantiated only once and is reused by each test case. int ans; boo原创 2013-10-08 02:13:10 · 479 阅读 · 0 评论 -
【leetcode】Search in Rotated Sorted Array
class Solution {public: int search(int A[], int n, int target) { // Note: The Solution object is instantiated only once and is reused by each test case. int sta=0,end=n-1;原创 2013-10-08 02:52:01 · 337 阅读 · 0 评论 -
【leetcode】3Sum
class Solution {public: vector > threeSum(vector &num) { // Note: The Solution object is instantiated only once and is reused by each test case. vector >ans; if(n原创 2013-10-08 01:39:53 · 405 阅读 · 0 评论 -
【leetcode】Roman to Integer
class Solution {public: int romanToInt(string s) { // Note: The Solution object is instantiated only once and is reused by each test case. int n=s.size(); if(n==0)原创 2013-10-08 00:48:31 · 383 阅读 · 0 评论 -
【leetcode】Set Matrix Zeroes
class Solution {public: void setZeroes(vector > &matrix) { // Note: The Solution object is instantiated only once and is reused by each test case. int rowLen=matrix.size()原创 2013-10-07 21:57:48 · 397 阅读 · 0 评论 -
【leetcode】Implement strStr()
class Solution {public: void getPre(char *needle,vector &pre,int neeLen)//对目标串,产生一个部分匹配的数组 { int k; pre[0]=-1; for(int i=1;i<neeLen;i++) { k=pre[i原创 2013-10-07 19:40:49 · 506 阅读 · 0 评论 -
【leetcode】Maximum Subarray
class Solution {public: int maxSubArray(int A[], int n) { // Start typing your C/C++ solution below // DO NOT write int main() function if(n==0) return 0;原创 2013-09-22 20:14:33 · 729 阅读 · 0 评论 -
【leetcode】Valid Palindrome
class Solution {public: bool check1(char ch)//当ch在'a'-'z'之间时,返回true { if(ch>='a'&&ch<='z') return true; return false; } bool check2(char ch)//当ch原创 2013-10-07 22:36:42 · 437 阅读 · 0 评论 -
【leetcode】Binary Tree Level Order Traversal
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Soluti原创 2013-10-07 13:47:53 · 446 阅读 · 0 评论 -
【leetcode】Merge Sorted Array
class Solution {public: void merge(int A[], int m, int B[], int n) { // Note: The Solution object is instantiated only once and is reused by each test case. vector tmp(m+n,0);//O(原创 2013-10-06 20:39:00 · 352 阅读 · 0 评论 -
【leetcode】Remove Duplicates from Sorted Array
class Solution {public: int removeDuplicates(int A[], int n) { // Note: The Solution object is instantiated only once and is reused by each test case. int groupNum=0;原创 2013-10-06 01:54:54 · 513 阅读 · 0 评论 -
【leetcode】Remove Duplicates from Sorted Array II
class Solution {public: int removeDuplicates(int A[], int n) { // Start typing your C/C++ solution below // DO NOT write int main() function if(n==0||n==1||n==2)//n<=2的情况原创 2013-10-06 19:59:08 · 452 阅读 · 0 评论 -
【leetcode】Partition List
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode *pa原创 2013-09-22 00:55:38 · 448 阅读 · 0 评论 -
【leetcode】Remove Duplicates from Sorted List
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode *de原创 2013-09-21 20:58:57 · 490 阅读 · 0 评论 -
【leetcode】Combinations
class Solution {public: vector >ans; vectortmp; void dfs(int dep,int maxDep,int start,int end) { if(dep==maxDep) { ans.push_back(tmp); re原创 2013-10-09 00:28:18 · 422 阅读 · 0 评论 -
【leetcode】Climbing Stairs
class Solution {public: int f[10000]={0};//初始化为全0 int climbStairs(int n) { // Start typing your C/C++ solution below // DO NOT write int main() function f[1]=1,f[2]=2原创 2013-09-22 19:56:11 · 407 阅读 · 0 评论 -
【leetcode】Convert Sorted List to Binary Search Tree
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; *//** * Definition for binary tree * stru原创 2013-09-22 19:43:12 · 506 阅读 · 0 评论 -
【leetcode】Search a 2D Matrix
class Solution {public: bool searchMatrix(vector > &matrix, int target) { // Note: The Solution object is instantiated only once and is reused by each test case. int m=matrix.size原创 2013-10-13 01:39:07 · 363 阅读 · 0 评论 -
【leetcode】Pow(x, n)
class Solution {public: double powPositive(double x,int n) { if(n==0)return 1; if(n==1)return x; double tmp; if(n%2==0) { tmp=pow原创 2013-10-11 22:16:07 · 463 阅读 · 0 评论 -
【leetcode】Decode Ways
class Solution {public: int numDecodings(string s) { // Start typing your C/C++ solution below // DO NOT write int main() function if(s.size()==0) return 0;原创 2013-09-24 23:18:12 · 389 阅读 · 0 评论 -
【leetcode】Permutations
class Solution {public: vector > permute(vector &num) { // Note: The Solution object is instantiated only once and is reused by each test case. vector >ans; sort(num.begin原创 2013-10-10 15:57:03 · 364 阅读 · 0 评论 -
【leetcode】String to Integer (atoi)
class Solution {public: int atoi(const char *str) { // Start typing your C/C++ solution below // DO NOT write int main() function bool negative=false; while(*str==原创 2013-09-25 08:54:27 · 379 阅读 · 0 评论 -
【leetcode】Next Permutation
class Solution {public: void nextPermutation(vector &num) { // Note: The Solution object is instantiated only once and is reused by each test case. for(int i=num.size()-2;i>=0;i--原创 2013-10-10 15:39:46 · 373 阅读 · 0 评论 -
【leetcode】Permutations II
class Solution {public: vector > permuteUnique(vector &num) { // Note: The Solution object is instantiated only once and is reused by each test case. vector >ans; sort(num原创 2013-10-11 01:55:16 · 434 阅读 · 0 评论 -
【leetcode】Single Number II
class Solution {public: int singleNumber(int A[], int n) { // Note: The Solution object is instantiated only once and is reused by each test case. int x[32];//记录A[]中的每一位 m原创 2013-10-11 01:23:55 · 715 阅读 · 0 评论 -
【leetcode】Single Number
class Solution {public: int singleNumber(int A[], int n) { // Note: The Solution object is instantiated only once and is reused by each test case. int ans=0; for(int i=0;i原创 2013-10-10 23:33:24 · 399 阅读 · 0 评论 -
【leetcode】Minimum Path Sum
class Solution {public: int dp[1005][1005]; int minPathSum(vector > &grid) { // Start typing your C/C++ solution below // DO NOT write int main() function if(grid.siz原创 2013-09-24 11:29:30 · 405 阅读 · 0 评论 -
【leetcode】Edit Distance
class Solution {public: int map[1005][1005]; int minDistance(string word1, string word2) { // Start typing your C/C++ solution below // DO NOT write int main() function原创 2013-09-24 01:39:31 · 467 阅读 · 0 评论 -
【leetcode】Subsets
class Solution {public: vector > subsets(vector &S) { // Note: The Solution object is instantiated only once and is reused by each test case. int N=S.size(); sort原创 2013-10-09 00:46:37 · 477 阅读 · 0 评论 -
【leetcode】Sqrt(x)
class Solution {public: int sqrt(int x) { // Note: The Solution object is instantiated only once and is reused by each test case. int sta=0,end=x; while(sta<=end)//等号不能丢原创 2013-10-08 23:49:31 · 399 阅读 · 0 评论 -
【leetcode】Palindrome Number
class Solution {public: bool isPalindrome(int x) { // Note: The Solution object is instantiated only once and is reused by each test case. if(x<0) return false;原创 2013-10-08 23:29:47 · 374 阅读 · 0 评论 -
【leetcode】Plus One
class Solution {public: vector plusOne(vector &digits) { // Note: The Solution object is instantiated only once and is reused by each test case. reverse(digits.begin(),digits.end(原创 2013-10-08 21:48:24 · 375 阅读 · 0 评论 -
【leetcode】Add Binary
class Solution {public: string addBinary(string a, string b) { // Note: The Solution object is instantiated only once and is reused by each test case. reverse(a.begin(),a.end());原创 2013-10-08 20:24:38 · 401 阅读 · 0 评论 -
【leetcode】Path Sum II
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Soluti原创 2013-09-22 22:23:58 · 447 阅读 · 0 评论 -
【leetcode】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原创 2013-09-22 01:48:33 · 478 阅读 · 0 评论 -
【leetcode】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原创 2013-09-21 20:23:37 · 460 阅读 · 0 评论