自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(19)
  • 资源 (1)
  • 收藏
  • 关注

原创 LeetCode#168 Excel Sheet Column Title

key: here A to Z represent to 1 - 26 , so preform n - 1 in each loop to change it to 0 - 25 Runtime: 0 ms / beats 11.37% Reference:discussclass Solution {public: string convertToTitle(int n) {

2016-08-13 15:34:20 415

原创 LeetCode#171 Excel Sheet Column Number

key: math Runtime: 11 ms / beats 38.09% No referenceclass Solution {public: int titleToNumber(string s) { int col = 0; for(char i : s) { col = col * 26 + (i -

2016-08-13 11:36:00 351

原创 LeetCode#383 Ransom Note

key: map Runtime: 232 ms No referenceclass Solution {public: bool canConstruct(string ransomNote, string magazine) { bool res = true; map<char, int> m; for(auto i : magaz

2016-08-13 10:07:20 251

原创 LeetCode#237 Delete Node in a Linked List

key: Linked List Runtime: 16 ms / beats 15.47% No reference/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(

2016-08-10 17:55:56 251

原创 LeetCode#349 Intersection of Two Arrays

key: map–find & count Runtime: 16 ms / beats 19.77% No referenceclass Solution {public: vector<int> intersection(vector<int>& nums1, vector<int>& nums2) { vector<int> res; map<in

2016-08-10 16:55:46 218

原创 LeetCode#169 Majority Element

key: map Runtime: 44 ms/ beats 9.23% Reference: blogpublic: int majorityElement(vector<int>& nums) { map<int,int> mapcnt; map<int,int>::iterator iter; for(int i = 0; i < n

2016-08-05 14:34:59 271

原创 LeetCode#100 Same Tree

key: recursion Runtime: 0 ms / beats 17.62% No reference/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(i

2016-07-29 15:57:51 265

原创 LeetCode#283 Move Zeroes

key: two pointers Runtime: 20 ms / beats 27.77% No referenceclass Solution {public: void moveZeroes(vector<int>& nums) { int cnt = 0; for(int i = 0; i < nums.size(); i++)

2016-07-29 11:26:00 165

原创 LeetCode#226 Invert Binary Tree

key: recursion Runtime: 0 ms / beats 22.92% No reference/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(i

2016-07-29 10:48:21 185

原创 LeetCode#104 Maximum Depth of Binary Tree

key: recursion Runtime: 8 ms / beats 24.48% No reference/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(i

2016-07-29 10:40:11 294

原创 LeetCode#258 Add Digits

key: note that 9%9=0, and -1%9 = -1 Runtime: 8 ms/ beats 52.315 Reference: discussclass Solution {public: int addDigits(int num) { return 1+(num - 1)%9; }};

2016-07-29 09:34:29 229

原创 LeetCode#371 Sum of Two Integers

key: xor to get the sum, & to get the carry, use recursion Runtime: 0 ms/ beats 11.31% Reference:discussclass Solution {public: int getSum(int a, int b) { if(a == 0) return b

2016-07-28 18:20:58 181

原创 LeetCode#338 Counting Bits

key: make use of what’s produced before Runtime: 88 ms / beats 53.16% Reference: blog, discussclass Solution {public: vector<int> countBits(int num) { vector<int> res(num+1, 0);

2016-07-25 16:43:47 204

原创 LeetCode#344 Reverse String

key: traverse from backward Runtime: 16 ms / beats 9.99% No referenceclass Solution {public: string reverseString(string s) { string res(s); for(int i = s.size()-1; i>=0; i--)

2016-07-25 10:05:40 219

原创 LeetCode#24 Swap Nodes in Pairs

key: head node & two pointers Runtime: 4 ms / beats 3.86% Reference:discuss/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x)

2016-07-25 09:43:45 222

原创 LeetCode#21 Merge Two Sorted Lists

key: judge if the lists end Runtime: 8 ms / beats 73.38% No reference/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : va

2016-07-23 17:56:06 215

原创 LeetCode#20 Valid Parentheses

key: stack & special condition Runtime: 0 ms / beats 15.90% No referenceclass Solution {public: bool isValid(string s) { if(s.size()%2 != 0) return false; stack<char>

2016-07-23 17:12:42 267

原创 LeetCode#19 Remove Nth Node From End of List

key: two pointers, one runs fast than the other n+1 steps Runtime: 4 ms / beats 37.25% Reference:discuss/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode

2016-07-23 15:53:00 237

原创 LeetCode#13 Roman to Integer

LeetCode#13 Roman to Integerkey: traverse the string from backwards Runtime: 44 ms / beats 52.85% Reference:discuss//I(1),X(10),C(100),M(1000),V(5),L(50),D(500)class Solution {public: int roman

2016-07-23 14:29:49 262

c语言二叉排序树代码

c语言二叉排序树代码,根据排序树特性组成的二叉树,利用中序遍历读出

2013-10-29

空空如也

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

TA关注的人

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