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

随笔分类 -  Leetcode

上一页 1 ··· 7 8 9 10 11 12 13 14 15 ··· 32 下一页
Leetcode: Plus One Linked List

摘要:Solution: Use Stack, O(N) space my another solution: don't create new node, modify the existed node Solution 3: reverse the inputs, add one, then reve 阅读全文
posted @ 2016-12-16 13:31 neverlandly 阅读(277) 评论(0) 推荐(0)
Leetcode: Sort Transformed Array

摘要:参考:https://discuss.leetcode.com/topic/48424/java-o-n-incredibly-short-yet-easy-to-understand-ac-solution the problem seems to have many cases a>0, a=0 阅读全文
posted @ 2016-12-16 12:31 neverlandly 阅读(220) 评论(0) 推荐(0)
Leetcode: Rearrange String k Distance Apart

摘要:Analysis: Solution 1: The greedy algorithm is that in each step, select the char with highest remaining count if possible (if it is not in the waiting 阅读全文
posted @ 2016-12-16 11:25 neverlandly 阅读(815) 评论(0) 推荐(0)
Leetcode: Line Reflection

摘要:本题精妙之处在于:1. 如何最快找到possible的line的x axis(我最开始想到要用quickselect find median的方法,结果别人有min max方法) 2. 如何最方便确定一个点关于该line的reflection是否存在,由于既有x又有y,不太好处理,别人有个聪明的办法 阅读全文
posted @ 2016-12-16 06:24 neverlandly 阅读(249) 评论(0) 推荐(0)
Leetcode: Logger Rate Limiter

摘要:HashMap 阅读全文
posted @ 2016-12-16 05:10 neverlandly 阅读(400) 评论(0) 推荐(0)
Leetcode: Design Snake Game

摘要:HashSet + Queue: 吃东西的时候保留尾巴,不吃的时候删去尾巴 one case to notice蛇转弯的时候,要先删去尾巴,再把新的点加进去。如果这个顺序不对的话,本来不会撞上尾巴的结果会判断会撞上 如果没有39行,程序会说dir没有initialize, 其实更好的写法应该是 阅读全文
posted @ 2016-12-16 04:53 neverlandly 阅读(520) 评论(0) 推荐(0)
Leetcode: Android Unlock Patterns

摘要:我自己的backtracking做法 最开始把cur设置为一个dummy value 0 最好的DFS with Optimization beat 97%: https://discuss.leetcode.com/topic/46260/java-dfs-solution-with-clear- 阅读全文
posted @ 2016-12-16 02:01 neverlandly 阅读(539) 评论(0) 推荐(0)
Leetcode: Longest Substring with At Most K Distinct Characters && Summary: Window做法两种思路总结

摘要:我的做法:维护一个window,r移动到超出k distinct character限制是更新max,然后移动l使distinct character <=k; 这种做法更新max只发生在超出限制的时候,有可能永远都没有超出限制,所以while loop完了之后要补上一个max的更新 别人非常棒的做 阅读全文
posted @ 2016-12-15 11:41 neverlandly 阅读(206) 评论(0) 推荐(0)
Design Tic-Tac Toe

摘要:Hint: 看了hint之后想到:既然用数组的话,一行一列都是一个element来代表,估计这个element是要用sum了,那么,能不能用sum来代表一行,使它有且只有一种可能,全部是player1完成的/全部是Player2;所以想到了是Player1就+1,是player2就-1,看最后sum 阅读全文
posted @ 2016-12-15 10:59 neverlandly 阅读(387) 评论(0) 推荐(0)
Leetcode: Moving Average from Data Stream

摘要:Queue method: Array method: 非常聪明 阅读全文
posted @ 2016-12-15 09:54 neverlandly 阅读(392) 评论(0) 推荐(0)
Leetcode: Nested List Weight Sum II

摘要:Inspired by: https://discuss.leetcode.com/topic/49041/no-depth-variable-no-multiplication Instead of multiplying by depth, add integers multiple times 阅读全文
posted @ 2016-12-15 07:35 neverlandly 阅读(654) 评论(0) 推荐(0)
Leetcode: Nested List Weight Sum

摘要:DFS: 阅读全文
posted @ 2016-12-15 06:31 neverlandly 阅读(266) 评论(0) 推荐(0)
Leetcode: Largest BST Subtree

摘要:refer to https://discuss.leetcode.com/topic/36995/share-my-o-n-java-code-with-brief-explanation-and-comments/2 这道题不好从root到leaf一层一层限制subtree取值范围,因为有可能p 阅读全文
posted @ 2016-12-15 05:59 neverlandly 阅读(329) 评论(0) 推荐(0)
Leetcode: Wiggle Sort II

摘要:这道题应该是hard,首先思想上面参考了https://discuss.leetcode.com/topic/32861/3-lines-python-with-explanation-proof I put the smaller half of the numbers on the even i 阅读全文
posted @ 2016-12-15 03:36 neverlandly 阅读(473) 评论(0) 推荐(0)
Leetcode: Sort Characters By Frequency

摘要:Bucket Sort + HashMap HashMap+ Heap+Wrapper Class 阅读全文
posted @ 2016-12-14 13:37 neverlandly 阅读(292) 评论(0) 推荐(0)
Leetcode: Delete Node in a BST

摘要:recursively find the node that needs to be deleted Once the node is found, have to handle the below 4 cases node doesn't have left nor right - return 阅读全文
posted @ 2016-12-14 12:19 neverlandly 阅读(497) 评论(0) 推荐(0)
Leetcode: Add Two Numbers II

摘要:The key of this problem is to think of using Stack 阅读全文
posted @ 2016-12-14 10:54 neverlandly 阅读(282) 评论(0) 推荐(0)
Leetcode: Find All Numbers Disappeared in an Array

摘要:Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once. Find all the elements of [1, n] inclusive that do not appear in this array. Cou... 阅读全文
posted @ 2016-12-13 12:36 neverlandly 阅读(435) 评论(0) 推荐(0)
Leetcode: Find All Duplicates in an Array

摘要:my solution: put integer A[i] at index A[i]-1 unless A[i] already equals i +1 or A[i] == A[A[i]-1] later scan again if at index i, A[i] != i+1, then A 阅读全文
posted @ 2016-12-13 12:12 neverlandly 阅读(325) 评论(0) 推荐(0)
Leetcode: Minimum Genetic Mutation

摘要:the same with word ladder 写的时候语法上出了一些问题 第5行不用给char数组赋大小 第20行用stringbuilder的时候曾经写成:String afterMutation = new StringBuilder(cur).setCharAt(i, c).toStri 阅读全文
posted @ 2016-12-13 11:03 neverlandly 阅读(1075) 评论(0) 推荐(0)

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