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

随笔分类 -  Leetcode

上一页 1 ··· 8 9 10 11 12 13 14 15 16 ··· 32 下一页
Leetcode: Island Perimeter

摘要:You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The grid is completely... 阅读全文
posted @ 2016-12-13 08:37 neverlandly 阅读(295) 评论(0) 推荐(0)
Leetcode: Can I Win

摘要:refer to https://discuss.leetcode.com/topic/68896/java-solution-using-hashmap-with-detailed-explanation After solving several "Game Playing" questions 阅读全文
posted @ 2016-12-13 07:59 neverlandly 阅读(1145) 评论(0) 推荐(0)
Leetcode: Repeated Substring Pattern

摘要:这道题应该没法用DP等解,只能brute force 或者 KMP(为深究) BruteForce, Best Solution for now except KMP 作为Encode String with Shortest Length的subproblem KMP解法未研究,https://d 阅读全文
posted @ 2016-12-13 04:43 neverlandly 阅读(730) 评论(0) 推荐(0)
Leetcode: Assign Cookies

摘要:Solution 1: Greedy, Time:O(nlogn) Just assign the cookies starting from the child with less greediness to maximize the number of happy children . Solu 阅读全文
posted @ 2016-12-13 02:23 neverlandly 阅读(332) 评论(0) 推荐(0)
Leetcode: 132 Pattern

摘要:我觉得这道题是hard,难点第一是要想到用stack,第二是要维护一个这样子的min-max序列:So at any time in the stack, non-overlapping Pairs are formed in descending order by their min value, 阅读全文
posted @ 2016-12-12 06:38 neverlandly 阅读(651) 评论(0) 推荐(0)
Leetcode: Arithmetic Slices II - Subsequence

摘要:参考了https://discuss.leetcode.com/topic/67413/detailed-explanation-for-java-o-n-2-solution 这道题DP思路还是能想出来,Time O(N^2), Space O(N^2) T(i, d), which denote 阅读全文
posted @ 2016-12-12 02:22 neverlandly 阅读(612) 评论(0) 推荐(0)
Leetcode: Minimum Moves to Equal Array Elements II

摘要:Just like meeting point problem, find the median elements in the array after sorting, so Solution 1: Sort, find the median: O(NlogN) Solution 2: Quick 阅读全文
posted @ 2016-12-10 02:59 neverlandly 阅读(407) 评论(0) 推荐(0)
Leetcode: 4Sum II

摘要:一开始想了一个O(n^3), space O(N)的做法,后来发现还可以优化 Solution: time O(N^2), space O(N^2) 阅读全文
posted @ 2016-12-09 01:03 neverlandly 阅读(328) 评论(0) 推荐(0)
Leetcode: K-th Smallest in Lexicographical Order

摘要:第二遍做法:参考https://discuss.leetcode.com/topic/64624/concise-easy-to-understand-java-5ms-solution-with-explaination Actually this is a denary tree (each n 阅读全文
posted @ 2016-12-08 07:37 neverlandly 阅读(620) 评论(0) 推荐(0)
Leetcode: Minimum Number of Arrows to Burst Balloons

摘要:我的Greedy+Heap做法: Array按start moment升序sort,Heap里按end moment升序sort,一旦到Heap里结束时间最早的气球的end,就要扔arrow,这时在heap里的气球都会被引爆 改进:因为一旦气球爆了的话,Heap里面的元素要全部清空,不需要知道Hea 阅读全文
posted @ 2016-12-08 04:33 neverlandly 阅读(474) 评论(0) 推荐(0)
Leetcode: Minimum Moves to Equal Array Elements

摘要:idea 1: suppose it takes y steps to equal each elements, then this equation stands: (min + y) * num.length == sum + (num.length-1)*y, where min + y is 阅读全文
posted @ 2016-12-08 00:48 neverlandly 阅读(386) 评论(0) 推荐(0)
Leetcode: Number of Boomerangs

摘要:Solution: Use HashTable, Time: O(N^2), Space: O(N) 我的:注意14行是有value个重复distance,表示有value个点,他们跟指定点距离都是distance,需要选取2个做permutation, 所以是value * (value-1) 别 阅读全文
posted @ 2016-12-07 13:51 neverlandly 阅读(494) 评论(0) 推荐(0)
Leetcode: Arranging Coins

摘要:count is the # of level, sum is the accumulated coins Better Solution: Binary Search, 因为怕溢出,所以(1+m)m/2表示成了line6那种样子. 用m去估计最后返回的row 阅读全文
posted @ 2016-12-07 13:44 neverlandly 阅读(287) 评论(0) 推荐(0)
Leetcode: Path Sum III

摘要:Add the prefix sum to the hashMap, and check along path if hashMap.contains(pathSum+cur.val-target); My Solution 一个更简洁的solution: using HashMap to stor 阅读全文
posted @ 2016-12-07 12:17 neverlandly 阅读(607) 评论(0) 推荐(0)
Leetcode: All O`one Data Structure

摘要:Solution: O(1) time complexity 解题思路主要参考了网友ivancjw的帖子,数据结构参考了https://discuss.leetcode.com/topic/65634/java-ac-all-strict-o-1-not-average-o-1-easy-to-re 阅读全文
posted @ 2016-12-07 09:09 neverlandly 阅读(1422) 评论(0) 推荐(0)
Leetcode: Find Right Interval

摘要:Solution 1: TreeMap, Time complexity: O(NlogN) 像这种在一个集合里面寻找有没有比某个数小的数,一般要么treeMap要么treeSet。Interval的题经常需要用treeMap, Data Stream as Disjoint Intervals 就 阅读全文
posted @ 2016-12-07 04:53 neverlandly 阅读(448) 评论(0) 推荐(0)
Leetcode: Non-overlapping Intervals

摘要:Actually, the problem is the same as "Given a collection of intervals, find the maximum number of intervals that are non-overlapping." (the classic Gr 阅读全文
posted @ 2016-12-07 01:28 neverlandly 阅读(762) 评论(0) 推荐(0)
Leetcode: Number of Segments in a String

摘要:用split() 不用API, better solution, O(N) time O(1) space 阅读全文
posted @ 2016-12-07 00:36 neverlandly 阅读(415) 评论(0) 推荐(0)
Leetcode: Strong Password Checker

摘要:refer to https://discuss.leetcode.com/topic/63854/o-n-java-solution-by-analyzing-changes-allowed-to-fix-each-problem http://www.cnblogs.com/grandyang/ 阅读全文
posted @ 2016-12-06 05:38 neverlandly 阅读(565) 评论(0) 推荐(0)
G 面经 && Leetcode: Longest Repeating Character Replacement

摘要:真是被这道题气死了,总是弄不对 The problem says that we can make at most k changes to the string (any character can be replaced with any other character). So, let's 阅读全文
posted @ 2016-12-05 13:58 neverlandly 阅读(437) 评论(0) 推荐(0)

上一页 1 ··· 8 9 10 11 12 13 14 15 16 ··· 32 下一页
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3