码迷,mamicode.com
首页 >  
搜索关键字:leetcode 19    ( 34993个结果
[Leetcode] Balanced Binary Tree
问题:给一个二叉树,写一个算法判断这个树是不是balanced。Solution #1.第一次遇到这个问题时我的解法,如下:public class Solution { public boolean isBalanced(TreeNode root) { if(root == ...
分类:其他好文   时间:2014-05-05 12:50:49    阅读次数:263
【LeetCode】Jump Game
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximu...
分类:其他好文   时间:2014-05-05 10:05:58    阅读次数:300
LeetCode OJ - Balanced Binary Tree
判断树是否是平衡的,这道题中的平衡的概念是指任意节点的两个子树的高度相差不超过1,我用递归的方法把所有的节点的高度都计算了下,并且在计算的过程记录每个节点左右两颗子树的高度差,最后通过遍历这个高度差就可以知道是否是平衡的。下面是AC代码: 1 /** 2 * Given a binary...
分类:其他好文   时间:2014-05-05 09:54:44    阅读次数:378
LeetCode OJ - Symmetric Tree && Same Tree
这两道题,大同小异。 我都是用BFS,在遍历的过程,判断结构是否相同/对称,值是否相同。下面是AC代码: 1 /** 2 * Given a binary tree, check whether it is a mirror of itself (ie, symmetric aroun...
分类:其他好文   时间:2014-05-05 09:48:26    阅读次数:401
LeetCode OJ - Binary Tree Level Order Traversal 1 && 2
BFS以及它的扩展,我发现栈是个很好用的数据结构,特别是对于顺序需要颠倒的时候!!!这里有个重要的信息:可以用null来标识一个level的结束!!!下面是AC代码: 1 /** 2 * Given a binary tree, return the bottom-up level ord...
分类:其他好文   时间:2014-05-05 09:46:06    阅读次数:402
[LeetCode] 在一堆字符串中找出包含相同字符的 group的较快方法,题 Anagrams
题目:Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.class Solution {public: vector ...
分类:其他好文   时间:2014-05-04 20:48:08    阅读次数:608
LeetCode: plusOne 题解
Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at...
分类:其他好文   时间:2014-05-04 19:46:18    阅读次数:372
【LeetCode】Evaluate Reverse Polish Notation
题目 Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, *, /. Each operand may be an integer or another expression. Some examples: ["2...
分类:其他好文   时间:2014-05-04 18:34:44    阅读次数:272
LeetCode---Gas Station
明知道明早要考试,可还是忍不住打开电脑想水一题。不过还是在这题上WA了好几次....看见自己有多渣!有个道理发现了很久,直到今天才意识到它的严重性,反复的做题只能让你不断的巩固已有的知识,而对于新知识的探索是少只又少,所以必须要通过多读书来获取新的知识,这样才能够扩充知识面。而之前的我就是忽略了读书...
分类:其他好文   时间:2014-05-04 12:18:21    阅读次数:218
二叉树的遍历--非递归实现
leetcode中有这么一道题,非递归来实现二叉树的遍历。二叉树的后序遍历顺序为,root->left, root->right, root,因此需要保存根节点的状态。显然使用栈来模拟递归的过程,但是难点是怎么从root->right转换到root。方法1:对于节点p可以分情况讨论1. p如果是叶子...
分类:其他好文   时间:2014-05-04 10:39:13    阅读次数:251
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!