- 博客(26)
- 资源 (1)
- 收藏
- 关注
原创 笛卡尔树构建
//// main.cpp// 数列构建笛卡尔树//#include using namespace std;/* 35 / \ 16 27 / \ / \ 12 15 19 18 12
2014-09-23 17:24:07
1041
原创 LeetCode-Triangle
int minimumTotal(vector > &triangle){ int n=triangle.size(); for(int layer=n-2; layer>=0; --layer) { for(int i=0; i<=layer; ++i) { triangle[layer][i] = mi
2014-09-22 20:13:31
354
原创 LeetCode-Path Sum II
class Solution {public: vector > pathSum(TreeNode *root, int sum){ vector >vec; vector path; if(root==NULL) return vec; FindPathSum(root, sum, 0, vec, path); return
2014-09-21 11:55:27
389
原创 LeetCode-3Sum Closest
class Solution {public: int threeSumClosest(vector &num, int target){ int result=0; int Min=INT_MAX; sort(num.begin(), num.end()); vector::iterator iter=num.begin(); for
2014-09-20 21:25:18
419
转载 LeetCode-Valid Sudoku
class Solution {public: bool isValidSudoku(vector > &board) { bool used[9]; for(int i=0; i<9; ++i) { fill(used, used+9, false);
2014-09-16 11:45:16
351
原创 LeetCode-Search in Rotated Sorted Array
int search(int A[], int n, int target){ if(A==0 || n==0) return -1; int left = 0; int right = n-1; while(left<=right) { int mid =left+((right-left)>>1);
2014-09-14 00:17:18
385
原创 LeetCode-Palindrome Number
bool isPalindrome(int x){ if(x<0) return false; if(0<=x && x<=9) return true; long long m=x,temp=0; while(m!=0) { temp=temp*10+m%10; m/=10;
2014-09-12 10:59:52
450
原创 LeetCode-Length of Last Word
int lengthOfLastWord(const char *s){ if(s==NULL) return 0; int length=0; int temp=0; for(int i=0; s[i]!='\0'; ++i) { if(s[i]==' ') { if(le
2014-09-12 10:46:24
424
原创 LeetCode-Minimum Depth of Binary Tree
int depth(TreeNode *root, int sum){ if(root->left==NULL && root->right==NULL) return sum; if(root->left==NULL) return depth(root->right,sum+1); if(root->right==NULL)
2014-09-12 10:23:38
392
原创 LeetCode-Remove Nth Node From End of List
ListNode *removeNthFromEnd(ListNode *head, int n){ if(head==NULL || (head->next==NULL && n==1)) return NULL; ListNode *pNode = head; int length=0; while(pNode!=NULL
2014-09-12 00:07:00
331
原创 LeetCode-Combinations
void comb(int n, int index, int k, vector > &res, vector &temp){ if(temp.size()==k) res.push_back(temp); for(int i=index; i<=n; ++i) { temp.push_back(i); comb
2014-09-10 10:25:34
360
原创 LeetCode-Path Sum
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Soluti
2014-09-09 00:25:58
371
原创 LeetCode-Remove Duplicates from Sorted Array II
class Solution {public: int Duplicate(int i,int A[]){ int count=1; for(int j=i+1;A[i]==A[j];j++) { count++; } return count;}int removeDuplicates(int A[], int n){
2014-06-06 00:28:59
325
原创 LeetCode-Merge Two Sorted Lists
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode *me
2014-04-22 14:59:18
353
原创 LeetCode-Linked List Cycle
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: bool hasCycl
2014-04-22 14:55:27
277
原创 LeetCode-Search Insert Position
class Solution {//简单的二分搜索变形public: int searchInsert(int A[], int n, int target) { int low=0; int high=n-1; int mid; while(low<=high) { mid=low+((high-low
2014-04-22 14:52:29
358
原创 LeetCode-Sort Colors
class Solution {public: void sortColors(int Array[], int length) { if(Array==NULL||length<=0) return ; int current; int begin; int end; current=begin=0;
2014-04-22 14:49:42
302
原创 LeetCode-N-Queens II
class Solution {public: int tot;int c[100];void search(int cur,int n)//cur代表着行,i代表着列{ int i,j; int ok; if(cur==n) tot++; else { for(i=0;i<n;i++) {
2014-04-22 14:47:16
320
原创 LeetCode-Gray Code
class Solution {public: vector grayCode(int n) { vector ans; int size = 1 << n; for(int i = 0; i < size; ++i) ans.push_back((i >> 1)^i); return ans;
2014-04-22 14:44:00
499
原创 LeetCode-Swap Nodes in Pairs
#include using namespace std;struct ListNode{ int val; ListNode *next;};void Swap(int *a,int *b){ int temp=*a; *a=*b; *b=temp;}ListNode *swapPairs(ListNode *head){ if
2014-04-20 21:23:50
595
原创 LeetCode-Remove Duplicates from Sorted Array
//双指针思想,但是还是wa了ha#include using namespace std;int removeDuplicates(int A[], int n){ if(n>=1) { int start = 0; A[start]=A[0]; for(int i = 1; i < n; i++)
2014-04-20 17:13:40
487
原创 LeetCode-Remove Duplicates from Sorted List
#include using namespace std;struct ListNode{ int val; ListNode* next;};ListNode* deleteDuplicates(ListNode *head){ if(head==NULL) return NULL; ListNode* pNode=hea
2014-04-20 16:40:36
335
原创 LeetCode-Convert Sorted Array to Binary Search Tree
#include #include using namespace std;struct TreeNode{ int val; TreeNode* left; TreeNode* right;};TreeNode* ArrayToBST(vector&num,int left,int right){ if(left>right) r
2014-04-20 16:36:30
355
原创 一点感想
现在大三了,大一大二本想练习acm,但是学校没有社团,宿舍的同学都在忙于上课的作业和电脑游戏,让我有一点小失望,不过自己学习一些acm的算法不会有坏处,反而我很喜欢acm,每天如果只是看看微博,刷刷新闻,会很无聊,还是在一年前的十一期间与一位计算机的朋友聊了聊,觉得还是得提高coding的能力,这位朋友现在进了谷歌,我虽然很羡慕,但是我却不嫉妒,因为他应经付出了很多,总是自己一人在coding,这
2013-11-21 23:49:43
605
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人