• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
neverlandly
博客园    首页    新随笔    联系   管理    订阅  订阅
2015年12月26日
Leetcode: Find the Duplicate Number
摘要: 参考了这个总结,非常详细:http://segmentfault.com/a/1190000003817671 最好方法: 映射找环法 复杂度 时间 O(N) 空间 O(1) 思路 假设数组中没有重复,那我们可以做到这么一点,就是将数组的下标和1到n每一个数一对一的映射起来。比如数组是213,则映射 阅读全文
posted @ 2015-12-26 13:56 neverlandly 阅读(321) 评论(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 阅读(396) 评论(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 阅读(358) 评论(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 阅读(470) 评论(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 阅读(391) 评论(0) 推荐(0)
Leetcode: Zigzag Iterator
摘要: Best Solution: O(N) This solution also works for K vectors Use a queue to store the iterators in different vectors. Every time we call next(), we pop 阅读全文
posted @ 2015-12-26 08:11 neverlandly 阅读(349) 评论(0) 推荐(0)
Leetcode: Wiggle Sort
摘要: Given an unsorted array nums, reorder it in-place such that nums[0] = nums[2] = nums[i - 1]如果i是偶数,nums[i] nums[i - 1], 则交换以后肯定有nums[i] =nums[i-1])) {... 阅读全文
posted @ 2015-12-26 07:38 neverlandly 阅读(300) 评论(0) 推荐(0)
Leetcode: Perfect Squares
摘要: Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n.For example, given n = 12, ... 阅读全文
posted @ 2015-12-26 04:57 neverlandly 阅读(260) 评论(0) 推荐(0)
Leetcode: First Bad Version
摘要: You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality c... 阅读全文
posted @ 2015-12-26 02:43 neverlandly 阅读(241) 评论(0) 推荐(0)
Leetcode: Find the Celebrity
摘要: 最佳做法:O(N)time, O(1)space The first pass is to pick out the candidate. If candidate knows i, then switch candidate. The second pass is to check whether 阅读全文
posted @ 2015-12-26 01:46 neverlandly 阅读(378) 评论(0) 推荐(0)
Leetcode: Integer to English Words
摘要: Career Cup 150 Pg 442 Think of Convert(19,323,984) = Process(19) + "million" + Process(323) + "thousand" + Process(984) + "" The Process is a process 阅读全文
posted @ 2015-12-26 00:08 neverlandly 阅读(376) 评论(0) 推荐(0)
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3