leetcode
ChenJingPiao
Learn by writing.
展开
-
LeetCode 344. Reverse String C语言
这道题很简单,前后两个“指针”,一个前移,一个后移。```char* reverseString(char* s) { int i=0,j=strlen(s)-1; char t; while(i { t=s[i]; s[i]=s[j]; s[j]=t; i++;原创 2016-04-24 19:31:54 · 883 阅读 · 0 评论 -
LeetCode 242. Valid Anagram C语言
Given two strings s and t, write a function to determine if t is an anagram of s.For example,s = "anagram", t = "nagaram", return true.s = "rat", t = "car", return false.首先是要两个字符串的长度想等;然原创 2016-04-24 21:00:44 · 484 阅读 · 0 评论 -
LeetCode 100. Same Tree C语言
Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.树的问题最容易想到的原创 2016-04-24 20:55:51 · 737 阅读 · 0 评论 -
LeetCode 237. Delete Node in a Linked List C语言
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value原创 2016-04-24 20:44:17 · 408 阅读 · 0 评论 -
LeetCode 283. Move Zeroes C语言
Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.For example, given nums = [0, 1, 0, 3, 12], after calling your原创 2016-04-24 20:33:42 · 278 阅读 · 0 评论 -
LeetCode 226. Invert Binary Tree C语言
树大都用了递归的思想,这到题也是;一颗只有根节点和叶子的二叉树,转置它是左右子树交换;左右子树转置又是这样,这样就是自己调用自己了;然后还要有递归的出口,当没有儿子的时候或者根节点为空时,返回自己,这个就是出口;/** * Definition for a binary tree node. * struct TreeNode { * int val; *原创 2016-04-24 20:16:28 · 529 阅读 · 0 评论 -
LeetCode 104. Maximum Depth of Binary Tree C语言
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.这到题最容易想出的方法是递归递归就是自己调用自己,数的子树又原创 2016-04-24 20:05:58 · 440 阅读 · 0 评论 -
LeetCode 258. Add Digits C语言
最朴素的方法,也是可以AC 的方法是循环,但是不符合题目要求int addDigits(int num) { return (num-1)%9+1;}时间复杂度是O(1),我们应该最先想到找规律。1 2 3 4 5 6 7 8 9 10 11 12 13 14 151 2 3 4 5 6 7 8 9 1 2 3 4 5 6答案为1-9中的一个,且循原创 2016-04-24 19:50:50 · 390 阅读 · 0 评论 -
LeetCode 292. Nim Game C语言
这到题代码很简单,要讲清楚不容易,最简单的是找规律,但是这还没讲出它的道理,等你们解释给我听。bool canWinNim(int n) { if(n%4==0) return 0; else return 1;}原创 2016-04-24 19:44:14 · 310 阅读 · 0 评论 -
LeetCode 338. Counting Bits C语言
Given a non negative integer number num. For every numbersi in the range 0 ≤ i ≤ num calculate the number of 1's in their binary representation and return them as an array.Example:For num = 5 yo原创 2016-04-28 20:58:51 · 678 阅读 · 0 评论 -
我在LeetCode的100题
我在LeetCode上面AC的只有94题,但是我思考的题目已经超过100题了。100题,我依然是菜鸟,不过算是入门了。我想回忆一下,算是总结与分享。一.我的小小经验很幸运一开始和师兄一起训练,如果不是的话我觉得很难坚持一下,因为我自己做题的话是不可能一道题做一个小时的。我觉得一道题思考这么长时间是有它的收获的,现在我也慢慢练习在一个人的情况下思考尽可能长的时间。相信我,思考的时间与收获成正比。模原创 2016-06-24 22:32:42 · 622 阅读 · 0 评论