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

随笔分类 -  Leetcode

上一页 1 ··· 11 12 13 14 15 16 17 18 19 ··· 32 下一页
Leetcode: Combination Sum IV && Summary: The Key to Solve DP

摘要:DP 解法: the key to solve DP problem is to think about how to create overlap, how to re-solve subproblems(怎么制造复用) Bottom up dp: Better Solution(Bottom-u 阅读全文
posted @ 2016-11-28 11:40 neverlandly 阅读(328) 评论(0) 推荐(0)
Leetcode: Wiggle Subsequence

摘要:DP solution is O(N^2), better way is greedy Now for explanation, we take example series:2,1,4,5,6,3,3,4,8,4 First we check if the series is starting a 阅读全文
posted @ 2016-11-28 10:26 neverlandly 阅读(533) 评论(0) 推荐(0)
Leetcode: Guess Number Higher or Lower II

摘要:Clarification of the problem: https://discuss.leetcode.com/topic/68252/clarification-on-the-problem-description-problem-description-need-to-be-updated 阅读全文
posted @ 2016-11-28 06:43 neverlandly 阅读(837) 评论(0) 推荐(0)
Leetcode: Guess Number Higher or Lower

摘要:Binary Search Here "My" means the number which is given for you to guess not the number you put into guess(int num). 阅读全文
posted @ 2016-11-28 05:33 neverlandly 阅读(401) 评论(0) 推荐(0)
Leetcode: Find K Pairs with Smallest Sums

摘要:Better Solution: O(KlogK), 转自https://discuss.leetcode.com/topic/50885/simple-java-o-klogk-solution-with-explanation Some observations: For every numbe 阅读全文
posted @ 2016-11-28 04:55 neverlandly 阅读(586) 评论(0) 推荐(0)
Leetcode: Super Pow

摘要:ab % k = (a%k)(b%k)%kSince the power here is an array, we'd better handle it digit by digit.One observation:a^1234567 % k = (a^1234560 % k) * (a^7 % k 阅读全文
posted @ 2016-11-28 01:48 neverlandly 阅读(398) 评论(0) 推荐(0)
Leetcode: Largest Divisible Subset

摘要:DP Solution similar to Longest Increasing Subsequence: 我的解法:用一个arraylist存以某一个element结尾的最长sequence 别人的好方法,大体思路一样,只是不存arraylist, 而用一个preIndex数组存以某一个elem 阅读全文
posted @ 2016-11-27 01:24 neverlandly 阅读(429) 评论(0) 推荐(0)
Leetcode: Water and Jug Problem && Summary: GCD求法(辗转相除法 or Euclidean algorithm)

摘要:参考:https://discuss.leetcode.com/topic/49238/math-solution-java-solution The basic idea is to use the property of Bézout's identity and check if z is a 阅读全文
posted @ 2016-11-27 00:10 neverlandly 阅读(655) 评论(0) 推荐(0)
Leetcode: Sum of Two Integers && Summary: Bit Manipulation

摘要:转自https://discuss.leetcode.com/topic/49771/java-simple-easy-understand-solution-with-explanation/2,注意里面对于减法的讲解 have been confused about bit manipulati 阅读全文
posted @ 2016-11-26 11:53 neverlandly 阅读(349) 评论(0) 推荐(0)
Leetcode: Max Sum of Rectangle No Larger Than K

摘要:Reference: https://discuss.leetcode.com/topic/48875/accepted-c-codes-with-explanation-and-references/2 The naive solution is brute-force, which is O(( 阅读全文
posted @ 2016-11-26 08:01 neverlandly 阅读(644) 评论(0) 推荐(0)
Leetcode: Count Numbers with Unique Digits

摘要:Analysis: A number of unique digits is a number which is a combination of unrepeated digits. So, we can calculate the total number. for number with n 阅读全文
posted @ 2016-11-26 04:20 neverlandly 阅读(340) 评论(0) 推荐(0)
Leetcode: Design Twitter

摘要:注意需要maintain一个time stamp, 每次postTweet时++。还有要注意unfollow的时候,不能unfollow自己 关于PriorityQueue还看到这一种写法,挺简单的: 1 Set<Integer> users = userMap.get(userId).follow 阅读全文
posted @ 2016-11-26 01:58 neverlandly 阅读(435) 评论(0) 推荐(0)
Leetcode: Nth Digit

摘要:1-9 : count:9 * len:1 10-99: count:90 * len:2 100-999: count:900 * len:3 1000-9999: count: 9000 * len:4 maintain a count, len, start 阅读全文
posted @ 2016-11-25 06:51 neverlandly 阅读(303) 评论(0) 推荐(0)
Leetcode: Russian Doll Envelopes

摘要:DP 解法, Time Complexity: O(N^2) sort based on width or height, anyone is ok. After the sorting, for each envelope, those envelopes which can fit into t 阅读全文
posted @ 2016-11-25 05:36 neverlandly 阅读(594) 评论(0) 推荐(0)
Leetcode: Data Stream as Disjoint Intervals && Summary of TreeMap

摘要:TreeMap 解法: Use TreeMap to easily find the lower and higher keys, the key is the start of the interval.Merge the lower and higher intervals when neces 阅读全文
posted @ 2016-11-25 02:06 neverlandly 阅读(420) 评论(0) 推荐(0)
Leetcode: Valid Perfect Square

摘要:我的binary Search 解法:无需变成long 别人三种方法总结: 阅读全文
posted @ 2016-11-24 12:50 neverlandly 阅读(330) 评论(0) 推荐(0)
Leetcode: Intersection of Two Arrays II

摘要:用HashMap Follow Up 1: 用two pointer解,可以省存成HashMap Follow Up 2: 用在长的数组里面binary Search可解 Follow Up 3: What if elements of nums2 are stored on disk, and t 阅读全文
posted @ 2016-11-24 11:52 neverlandly 阅读(285) 评论(0) 推荐(0)
Leetcode: Intersection of Two Arrays

摘要:Use two hash sets Time complexity: O(n) 注意Set<Integer> set = new HashSet<>(); 第二个泛型可以不写出 Iterator iter = set2.iterator(); for (int i=0; i<res.length; 阅读全文
posted @ 2016-11-24 10:34 neverlandly 阅读(319) 评论(0) 推荐(0)
Leetcode: Top K Frequent Elements

摘要:很像majority element III, 但是那道题有O(k) extra space的限制,这里没有。有任意extra space, 同时知道elem range情况下,bucket sort最节省时间 语法上注意第5行,建立一个ArrayList的array,后面没有泛型generic L 阅读全文
posted @ 2016-11-24 06:51 neverlandly 阅读(315) 评论(0) 推荐(0)
Leetcode: Reverse Vowels of a String

摘要:Two Pointers 解法, 注意大小写 阅读全文
posted @ 2016-11-24 05:20 neverlandly 阅读(273) 评论(0) 推荐(0)

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