自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(33)
  • 收藏
  • 关注

转载 Unique Paths II

class Solution { public: int uniquePathsWithObstacles(vector > &obstacleGrid) { // Start typing your C/C++ solution below // DO NOT write int main() function vector > f(obs

2014-11-13 15:17:46 180

原创 4Sum

class Solution { public: vector > fourSum(vector &num, int target) { vector > ret; int len = num.size(); if(len < 4) return ret; vector num2; num2.assign(num.begin(), num.end()); sort( num

2014-11-13 14:15:32 176

转载 Construct Binary Tree from Inorder and Postorder Traversal

/** /** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class So

2014-11-06 13:37:50 123

原创 Construct Binary Tree from Preorder and Inorder Traversal

/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class Soluti

2014-11-06 13:37:17 138

转载 Anagrams

class Solution { public: vector anagrams(vector &strs) { string s; map anagram; vector res; for (int i = 0; i < strs.size(); ++i) { s = strs[i];

2014-11-04 21:29:24 131

转载 Sudoku Solver

bool isValid(vector > &board, int a, int b) { for (int i = 0; i < 9; ++i) { if (i != a && board[i][b] == board[a][b]) return false; } for (int j = 0; j < 9; ++j) { if (j != b && board[a][j]

2014-11-04 17:00:25 130

原创 Valid Sudoku

class Solution { public: bool isLineOk(vector &board){ //1到9,没有重复 map roman; roman['1']=0; roman['2']=0; roman['3']=0; roman['4']=0; roman['5']=0; roman['6']=0; roman['7']=0; roman['8']=

2014-11-03 18:00:15 137

原创 Sort List

/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode *mergeT

2014-10-29 18:42:15 208

原创 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

2014-10-29 16:53:26 128

原创 Rotate List

/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode *ro

2014-10-29 15:06:16 213

原创 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

2014-10-28 15:04:26 172

原创 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

2014-10-27 15:39:48 121

原创 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-10-27 13:12:39 117

原创 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

2014-10-27 12:35:02 152

原创 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

2014-10-27 10:51:09 134

原创 Add Two Numbers

/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode *ad

2014-10-27 10:16:22 169

原创 Divide Two Integers

long long internalDivide(unsigned long long dividend,unsigned long long divisor){ if (dividend<divisor) { return 0; } long long result = 1; unsigned long long tmp = divisor,left; while (tmp<=d

2014-10-25 21:24:48 124

原创 Max Points on a Line

class Solution { public: //判断点是否在直线上,就是判断斜率是否相同 int maxPoints(vector &points) { int maxLine = 0; if(points.size() <=2) return points.size(); for (int

2014-10-25 21:23:25 179

原创 Integer to Roman

class Solution { public: string cc(int num){ if(num=0){ switch(num){ case 0: return "";break; case 1: return "I";break; case 2: return "II";break; case 3: return "III";break; case 4: retu

2014-10-24 15:15:53 189

原创 Multiply Strings

class Solution { public: string multiply(string num1, string num2) { stringstream ss; bool ispositive = true; vector s_num1; vector s_num2; //positive int length1 = num1.size(); int length2 = nu

2014-10-24 14:01:02 149

原创 Sqrt(x)

class Solution { public: int sqrt(int x) { if(x<0) return -1; if(x=0) return 0; int left = 0; int right = x; long long mid = 0;

2014-10-24 09:21:26 184

原创 Permutation Sequence

class Solution { public: int uniquePro(int n){ int sum = 1; while(n){ sum *= n; n--; } return sum; } string getPermutation(int n, int k) { stringstream ss; vector res; for(int i=1;i<=

2014-10-23 20:35:07 154

原创 String to Integer (atoi)

class Solution { public: int atoi(const char *str) { if(str == NULL) return 0; if(*str == '\0') return 0; long long res = 0; //去除空格 while(*str == ' ') str++; bool ispositive = t

2014-10-23 17:01:02 194

原创 Reverse Integer

class Solution { public: int reverse(int x) { int temp = x,temp1 = x; if(x<0){ temp *= -1; temp1 *= -1; } int result = 0; int wei = 1; while( temp >= 10){ wei++; temp /= 10;

2014-10-23 16:20:12 121

原创 Palindrome Number

class Solution { public: bool isPalindrome(int x) { int wei = 1; int result = x; if( x < 0) return false; while(result >= 10){ wei++;

2014-10-23 16:02:56 174

原创 Roman to Integer

class Solution { public: int romanToInt(string s) { map roman; roman['I']=1; roman['V']=5; roman['X']=10; roman['L']=50; roman['C']=100; roman['D']=500; roman['M']=1000; int length

2014-10-22 21:00:43 118

原创 Add Binary

class Solution { public: string addBinary(string a, string b) { string c; int ai = a.length()-1; int bi = b.length()-1; int ml = ai>bi?ai:bi; int q = 0; for(int i=0;i<=ml;i++,ai--,bi-

2014-10-22 19:45:11 254

原创 3Sum Closest

class Solution { public: int threeSumClosest(vector &num, int target) { int count = num.size(); int result = 0; sortPro(num); result = abs(num[0]+num[1]+num[2] -target); int cc = num[

2014-10-22 11:01:11 169

原创 Two Sum

class Solution { public: vector twoSum(vector &numbers, int target) { vector result; unordered_map mapping; for(int i=0;i<numbers.size();i++){ mapping[numbers[i]]=i; } for(int i=0;i<numbe

2014-10-21 21:23:04 183

原创 Plus One

class Solution { public: vector plusOne(vector &digits){ int count = digits.size(); digits[count-1] += 1; while(count--){ if(digits[count] >=10 && count >=1){ digits[count] %= 10; d

2014-10-21 20:29:41 164

原创 Merge Sorted Array

class Solution { public: void merge(int A[], int m, int B[], int n) { int length = m+n; int Ai = m-1; int Bi = n-1; for(int i=length-1 ;i>=0;i--){ if(Ai >=0 && Bi>=0){ if(A[Ai] >

2014-10-21 19:26:32 127

原创 Remove Element

class Solution { public: int removeElement(int A[], int n, int elem) { int index = 0; for(int i=0;i<n;i++){ if(A[i] != elem) A[index++] = A[i]; }

2014-10-21 16:31:01 200

原创 Remove Duplicates from Sorted Array II

class Solution { public: int removeDuplicates(int A[], int n) { if(n<1) return 0; if(n==1) return 1; int index = 2; for(int i=2;i<n;i++){

2014-10-21 14:25:55 142

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除