
leetcode
ak47b51c4
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
[leetcode]二叉树中序遍历非递归实现
二叉树中序遍历非递归实现 近日在刷Leetcode中有一道题,让你用非递归的方法实现二叉树的先序和中序遍历,先序遍历好说,根左右的顺序,维护一个栈,每次pop栈顶元素,访问,然后将其右节点,左节点依次压入(注意顺序!倒着来),直到栈为空时便结束了遍历,而实现中序遍历的非递归时,便遇到了不小的问题。 首先我们先从中序遍历的递归写法看起,写段简单的伪代码 InorderTraversal(原创 2016-03-31 00:41:13 · 367 阅读 · 0 评论 -
[leetcode] Contains Duplicate 判断一数组是否有重复元素
Given an array of integers and an integer k, return true if and only if there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between i and j is at most原创 2015-11-07 12:00:58 · 285 阅读 · 0 评论 -
[leetcode]Lowest Common Ancestor of a Binary Search Tree
Lowest Common Ancestor of a Binary Search Tree Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST. According to the definition of原创 2015-11-08 14:41:31 · 209 阅读 · 0 评论 -
[leetcode]题解+经验总结 自己做法+评论区mostvotes汇总 (只包含部分easy难度)
鉴于最近是实习季,可能有很多小伙伴在刷leetcode,我把easy部分刷到的一些有趣的题和大家分享下,也是为了复习总结下,每道题都包含了我自己的做法和评论区 Most Votes的做法,有些做法真令人眼前一亮,大家可以参考下。 注:我题目的顺序是按通过率排序的,如果你想找特定的题,可以尝试ctrl+f搜索题号。 0.leetcode 教给我们最重要的就是一定一定一定要考虑特殊值情原创 2016-03-21 20:36:39 · 833 阅读 · 0 评论 -
[leetcod] 从 “寻找故障机器” y&II 的一点启发
先从编程之美中一道叫做“寻找故障机器”的题目说起,题目大意是 一个数组,其中只有一个数字出现了一次,其他都出现了两次,问怎样快速找到那个出现了一次的数字。这也就是leetcode上Single Number I这道题。当然了,我们有个对于空间和时间的限制,限制空间为O(1),时间为线性的。若做过这种题,或者经过自己一步步的思考,或许可以想到这个巧妙的方法:将所有数组中的数全部抑或,最后剩下的那个,原创 2016-07-07 23:42:09 · 441 阅读 · 0 评论