摘要: LeetCode 242 Valid Anagram由于都是小写字母,可以建立一个长度为26的数组来记录每个字母出现的次数。C语言实现如下:bool isAnagram(char* s, char* t) { if(strlen(s)!=strlen(t)) return 0; ... 阅读全文
posted @ 2015-11-14 10:17 Walker_Lee 阅读(140) 评论(0) 推荐(0) 编辑
摘要: LeetCode 171 Excel Sheet Column Numberc语言实现:int titleToNumber(char* s) { int num = 0; char c; while(c = *s++) { num = num*26 + c - ... 阅读全文
posted @ 2015-11-14 09:30 Walker_Lee 阅读(107) 评论(0) 推荐(0) 编辑
摘要: LeetCode 217 Contains Duplicate一种C++实现,先排序,再比较相邻值是否相等:class Solution {public: bool containsDuplicate(vector& nums) { std::sort(nums.begin(),... 阅读全文
posted @ 2015-11-14 09:07 Walker_Lee 阅读(122) 评论(0) 推荐(0) 编辑
摘要: leetcode 226 Invert Binary Tree递归方法/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * stru... 阅读全文
posted @ 2015-10-17 16:28 Walker_Lee 阅读(117) 评论(0) 推荐(0) 编辑
摘要: LeetCode 283 Move Zeroesvoid moveZeroes(int* nums, int numsSize) { int i=0,j=0; for(i;ij) j=i; }} 阅读全文
posted @ 2015-10-17 16:12 Walker_Lee 阅读(112) 评论(0) 推荐(0) 编辑
摘要: LeetCode 100 Same Tree递归方法:/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeN... 阅读全文
posted @ 2015-10-17 10:51 Walker_Lee 阅读(96) 评论(0) 推荐(0) 编辑
摘要: LeetCode 237 Delete Node in a Linked List/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * };... 阅读全文
posted @ 2015-10-17 10:21 Walker_Lee 阅读(83) 评论(0) 推荐(0) 编辑
摘要: LeetCode 104 Maximum Depth of Binary Treehttps://leetcode.com/problems/maximum-depth-of-binary-tree//** * Definition for a binary tree node. * struct ... 阅读全文
posted @ 2015-10-17 10:10 Walker_Lee 阅读(89) 评论(0) 推荐(0) 编辑
摘要: LeetCode 292 Nim Gamehttps://leetcode.com/problems/nim-game/当能被4整除时,才会输。bool canWinNim(int n) { return n%4;} 阅读全文
posted @ 2015-10-14 19:27 Walker_Lee 阅读(89) 评论(0) 推荐(0) 编辑
摘要: LeetCode 258 Add Digitshttps://leetcode.com/problems/add-digits/该题主要用到了树根这个概念 ,百度百科链接:http://baike.baidu.com/view/5820558.htm#include int addDigits(in... 阅读全文
posted @ 2015-10-12 15:23 Walker_Lee 阅读(93) 评论(0) 推荐(0) 编辑