• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
neverlandly
博客园    首页    新随笔    联系   管理    订阅  订阅

随笔分类 -  Leetcode

上一页 1 ··· 14 15 16 17 18 19 20 21 22 ··· 32 下一页
Leetcode: Smallest Rectangle Enclosing Black Pixels

摘要:An image is represented by a binary matrix with 0 as a white pixel and 1 as a black pixel. The black pixels are connected, i.e., there is only one bla 阅读全文
posted @ 2015-12-29 08:28 neverlandly 阅读(942) 评论(0) 推荐(0)
Leetcode: Longest Increasing Subsequence

摘要:讲解一: 用一个数组来存 the smallest tail of all increasing subsequences with length i+1 in tails[i]. For example, say we have nums = [4,5,6,3], then all the ava 阅读全文
posted @ 2015-12-29 06:07 neverlandly 阅读(429) 评论(0) 推荐(0)
Leetcode: Bulls and Cows

摘要:Be careful, when calculate B, you should exclude A's cases 阅读全文
posted @ 2015-12-29 04:52 neverlandly 阅读(338) 评论(0) 推荐(0)
Leetcode: Serialize and Deserialize Binary Tree

摘要:Referring this post: https://leetcode.com/problems/serialize-and-deserialize-binary-tree/discuss/74253/Easy-to-understand-Java-Solution But instead us 阅读全文
posted @ 2015-12-29 03:16 neverlandly 阅读(378) 评论(0) 推荐(0)
Leetcode: Binary Tree Longest Consecutive Sequence

摘要:递归法 复杂度 时间O(n) 空间O(h) 思路 因为要找最长的连续路径,我们在遍历树的时候需要两个信息,一是目前连起来的路径(curLen)有多长(以当前节点为终点),二是目前路径的上一个节点的值(preVal)。 每一次递归,先检查当前节点是否比上一节点大1, 是,curLen++, 否curL 阅读全文
posted @ 2015-12-29 01:11 neverlandly 阅读(364) 评论(0) 推荐(0)
Leetcode: Best Meeting Point

摘要:A group of two or more people wants to meet and minimize the total travel distance. You are given a 2D grid of values 0 or 1, where each 1 marks the h... 阅读全文
posted @ 2015-12-28 12:06 neverlandly 阅读(291) 评论(0) 推荐(0)
Leetcode: Find Median from Data Stream

摘要:最大最小堆 复杂度 时间 O(logN) insert, O(1) query, 空间 O(N) 思路 维护一个最大堆,一个最小堆。最大堆存的是到目前为止较小的那一半数,最小堆存的是到目前为止较大的那一半数,这样中位数只有可能是堆顶或者堆顶两个数的均值。而维护两个堆的技巧在于判断堆顶数和新来的数的大 阅读全文
posted @ 2015-12-28 07:45 neverlandly 阅读(282) 评论(0) 推荐(0)
Leetcode: Flip Game II

摘要:You are playing the following Flip Game with your friend: Given a string that contains only these two characters: + and -, you and your friend take tu 阅读全文
posted @ 2015-12-28 06:05 neverlandly 阅读(541) 评论(0) 推荐(0)
Leetcode: Flip Game

摘要:You are playing the following Flip Game with your friend: Given a string that contains only these two characters: + and -, you and your friend take tu... 阅读全文
posted @ 2015-12-28 04:17 neverlandly 阅读(306) 评论(0) 推荐(0)
Leetcode: Nim Game

摘要:You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 ston... 阅读全文
posted @ 2015-12-28 02:17 neverlandly 阅读(227) 评论(0) 推荐(0)
Leetcode: Word Pattern II

摘要:Given a pattern and a string str, find if str follows the same pattern.Here follow means a full match, such that there is a bijection between a letter... 阅读全文
posted @ 2015-12-28 01:45 neverlandly 阅读(345) 评论(0) 推荐(0)
Leetcode: Word Pattern

摘要:Given a pattern and a string str, find if str follows the same pattern. Here follow means a full match, such that there is a bijection between a lette 阅读全文
posted @ 2015-12-28 00:54 neverlandly 阅读(330) 评论(0) 推荐(0)
Leetcode: Game of Life

摘要:编解码法 复杂度 时间 O(NN) 空间 O(1) 思路 最简单的方法是再建一个矩阵保存,不过当inplace解时,如果我们直接根据每个点周围的存活数量来修改当前值,由于矩阵是顺序遍历的,这样会影响到下一个点的计算。如何在修改值的同时又保证下一个点的计算不会被影响呢?实际上我们只要将值稍作编码就行了 阅读全文
posted @ 2015-12-27 13:18 neverlandly 阅读(510) 评论(0) 推荐(0)
Leetcode: Alien Dictionary && Summary: Topological Sort

摘要:There is a new alien language which uses the latin alphabet. However, the order among letters are unknown to you. You receive a list of words from the... 阅读全文
posted @ 2015-12-27 12:05 neverlandly 阅读(575) 评论(0) 推荐(0)
Leetcode: Unique Word Abbreviation

摘要:An abbreviation of a word follows the form . Below are some examples of word abbreviations:a) it --> it (no abbreviation) ... 阅读全文
posted @ 2015-12-27 07:14 neverlandly 阅读(383) 评论(0) 推荐(0)
Leetcode: Find the Duplicate Number

摘要:参考了这个总结,非常详细:http://segmentfault.com/a/1190000003817671 最好方法: 映射找环法 复杂度 时间 O(N) 空间 O(1) 思路 假设数组中没有重复,那我们可以做到这么一点,就是将数组的下标和1到n每一个数一对一的映射起来。比如数组是213,则映射 阅读全文
posted @ 2015-12-26 13:56 neverlandly 阅读(325) 评论(0) 推荐(0)
Leetcode: Walls and Gates

摘要:Push all gates into queue first. Then for each gate update its neighbor cells who is empty and push them to the queue. Repeating above steps until the 阅读全文
posted @ 2015-12-26 13:14 neverlandly 阅读(401) 评论(0) 推荐(0)
Leetcode: Move Zeroes

摘要:第二遍做法: 双指针压缩法:O(N), 空间:O(1) 实际上就是将所有的非0数向前尽可能的压缩,最后把没压缩的那部分全置0就行了。比如103040,先压缩成134,剩余的3为全置为0。过程中需要一个指针记录压缩到的位置。 Q:如果要把所有的0放在前面而不是后面呢?A:同样的解题思路,但是是从后向前 阅读全文
posted @ 2015-12-26 09:51 neverlandly 阅读(360) 评论(0) 推荐(0)
Leetcode: Peeking Iterator

摘要:My thinking is: use a double cache: long cache, when no number is cached, cache = Long.MIN_VALUE. When i call next(), it will firstly check if there's 阅读全文
posted @ 2015-12-26 09:42 neverlandly 阅读(471) 评论(0) 推荐(0)
Leetcode: Inorder Successor in BST

摘要:网上看到更好的方法:https://leetcode.com/discuss/77805/java-5ms-short-code-with-explanations The idea is to compare root's value with p's value if root is not n 阅读全文
posted @ 2015-12-26 08:49 neverlandly 阅读(392) 评论(0) 推荐(0)

上一页 1 ··· 14 15 16 17 18 19 20 21 22 ··· 32 下一页
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3