• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
neverlandly
博客园    首页    新随笔    联系   管理    订阅  订阅
上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 21 下一页
2016年12月7日
Leetcode: Number of Segments in a String
摘要: 用split() 不用API, better solution, O(N) time O(1) space 阅读全文
posted @ 2016-12-07 00:36 neverlandly 阅读(417) 评论(0) 推荐(0)
2016年12月6日
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 阅读(575) 评论(0) 推荐(0)
2016年12月5日
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 阅读(442) 评论(0) 推荐(0)
Leetcode: Reconstruct Original Digits from English
摘要: # of '0': # of 'z' # of '2': # of 'w' 4: u 6: x 8: g 3: h - 8 5: f - 4 7: s - 6 1: o - 0 - 2 - 4 9: i - 5 - 6 - 8 我的code用了一个数组来存char count 阅读全文
posted @ 2016-12-05 08:51 neverlandly 阅读(362) 评论(0) 推荐(0)
Leetcode: Maximum XOR of Two Numbers in an Array
摘要: Solution 1: Bit Manipulation: 这题真心有点难,get the max XOR bit by bit note that if A^B=C, then A^C=B, B^C=A Solution 2: Trie, (未研究) https://discuss.leetcod 阅读全文
posted @ 2016-12-05 07:48 neverlandly 阅读(552) 评论(0) 推荐(0)
Leetcode: Battleships in a Board
摘要: 只计算每个battleship的第一个元素,所以后面‘X’如果above或者left也是'X'的话,不被计算 阅读全文
posted @ 2016-12-05 06:10 neverlandly 阅读(431) 评论(0) 推荐(0)
Leetcode: Split Array Largest Sum
只有注册用户登录后才能阅读该文。 阅读全文
posted @ 2016-12-05 04:44 neverlandly 阅读(546) 评论(0) 推荐(0)
2016年12月3日
Leetcode: Find All Anagrams in a String
摘要: Time Complexity will be O(n) because the "start" and "end" points will only move from left to right once. Sliding Window: Use a count to denote the di 阅读全文
posted @ 2016-12-03 13:14 neverlandly 阅读(1403) 评论(0) 推荐(0)
Leetcode: Pacific Atlantic Water Flow
摘要: 这题考点在于需要设置两个visited数组 Two Queue and add all the Pacific border to one queue; Atlantic border to another queue. Keep a visited matrix for each queue. I 阅读全文
posted @ 2016-12-03 12:05 neverlandly 阅读(799) 评论(0) 推荐(0)
Leetcode: Partition Equal Subset Sum
摘要: Backpack problem: dp[i][j] means if the first i elements can sum up to value j dp[i][j] = dp[i-1][j] || (j>=nums[i-1] && dp[i-1][j-nums[i-1]]) the res 阅读全文
posted @ 2016-12-03 10:29 neverlandly 阅读(309) 评论(0) 推荐(0)
Leetcode: Third Maximum Number
摘要: My Solution: Highest votes in discussion 阅读全文
posted @ 2016-12-03 06:22 neverlandly 阅读(374) 评论(0) 推荐(0)
Leetcode: Arithmetic Slices
摘要: A slice (P, Q)其实就是从P到Q的序列,(P,Q)是arithmetic slice要求是等差数列且至少有三个数,问array里面有多少个这样的(P, Q) 这道题难点在于想到用DP,一旦想到用DP,就迎刃而解 dp[i]表示以i结束的slice有多少个 阅读全文
posted @ 2016-12-03 05:12 neverlandly 阅读(372) 评论(0) 推荐(0)
Leetcode: Trapping Rain Water II
摘要: The above image represents the elevation map [[1,4,3,1,3,2],[3,2,1,3,2,4],[2,3,3,2,3,1]] before the rain. After the rain, water are trapped between th 阅读全文
posted @ 2016-12-03 03:16 neverlandly 阅读(558) 评论(0) 推荐(0)
Leetcode: Remove K Digits
摘要: Greedy + Stack: 用一个栈维护最后要留存下来的digits 需要注意的是:如果遍历到string的某个char, string后面的char数刚刚好能填满这个栈,那么即使这个char比栈顶还要小,也不出栈,直接入栈 最后要删除leading 0 用char[]实现栈,思路一样,要快很多 阅读全文
posted @ 2016-12-03 00:24 neverlandly 阅读(439) 评论(0) 推荐(0)
2016年12月2日
Leetcode: Add Strings
摘要: Given two non-negative numbers num1 and num2 represented as string, return the sum of num1 and num2. Note: The length of both num1 and num2 is =0 || j>=0 || carry!=0) { 8 int sum = 0; ... 阅读全文
posted @ 2016-12-02 12:46 neverlandly 阅读(324) 评论(0) 推荐(0)
Leetcode: Longest Palindrome
摘要: Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters. This is case sensitive, for example "Aa" is not cons... 阅读全文
posted @ 2016-12-02 12:26 neverlandly 阅读(255) 评论(0) 推荐(0)
Leetcode: Queue Reconstruction by Height
摘要: refer to: https://discuss.leetcode.com/topic/60394/easy-concept-with-python-c-java-solution E.g.input: [[7,0], [4,4], [7,1], [5,0], [6,1], [5,2]]subar 阅读全文
posted @ 2016-12-02 11:58 neverlandly 阅读(371) 评论(0) 推荐(0)
Leetcode: Convert a Number to Hexadecimal
摘要: 记住要delete begining 0 要记住单独处理 num == 0的情况 阅读全文
posted @ 2016-12-02 11:06 neverlandly 阅读(409) 评论(0) 推荐(0)
Leetcode: Frog Jump
摘要: Solution 1: Backtracking, but will TLE Better Solution: DP (refer to https://discuss.leetcode.com/topic/59903/very-easy-to-understand-java-solution-wi 阅读全文
posted @ 2016-12-02 08:35 neverlandly 阅读(773) 评论(0) 推荐(0)
Leetcode: Binary Watch
摘要: Solution 1: Bit Manipulation use Integer.bitCount() Solution 2: Backtracking, 非常精妙之处在于用了两个数组来帮助generate digit(例如:1011 -> 11) 阅读全文
posted @ 2016-12-02 05:00 neverlandly 阅读(246) 评论(0) 推荐(0)
Leetcode: Evaluate Division
摘要: Graph, DFS (1) Build the map, the key is dividend, the value is also a map whose key is divisor and value is its parameter. For example, a / b = 2.0, 阅读全文
posted @ 2016-12-02 02:10 neverlandly 阅读(330) 评论(0) 推荐(0)
2016年12月1日
Leetcode: Fizz Buzz
摘要: Solution 1: Solution with out using % 阅读全文
posted @ 2016-12-01 12:46 neverlandly 阅读(423) 评论(0) 推荐(0)
Leetcode: Integer Replacement
摘要: Refer to: https://discuss.leetcode.com/topic/58334/a-couple-of-java-solutions-with-explanations/2 When to add 1 instead of minus 1, here is an example 阅读全文
posted @ 2016-12-01 12:31 neverlandly 阅读(366) 评论(0) 推荐(0)
Leetcode: Longest Substring with At Least K Repeating Characters
摘要: Analysis: Given a string s, find out all chars that are invalid (i.e., count < k). The longest substring must reside in one of the substrings divided 阅读全文
posted @ 2016-12-01 11:33 neverlandly 阅读(429) 评论(0) 推荐(0)
Leetcode: Rotate Function
摘要: F(0) = (0 * 4) + (1 * 3) + (2 * 2) + (3 * 6) = 0 + 3 + 4 + 18 = 25 [4, 3, 2, 6] F(1) = (0 * 6) + (1 * 4) + (2 * 3) + (3 * 2) = 0 + 4 + 6 + 6 = 16 [6, 阅读全文
posted @ 2016-12-01 08:12 neverlandly 阅读(226) 评论(0) 推荐(0)
Leetcode: UTF-8 Validation
摘要: 这道题题干给出了判断 one single UTF-8 char的方法,然后给一个UTF-8 char sequence,判断是不是正确sequence. (读题读了很久) 这道题关键是要学到用 & 取出一个bit sequence当中几位的方法 二进制数表示法:在前面加 0b, 八进制加0o, 十 阅读全文
posted @ 2016-12-01 07:09 neverlandly 阅读(733) 评论(0) 推荐(0)
Leetcode: Decode String
摘要: 自己的做法:这种括号问题肯定是用栈,最好是先在栈里存一个空元素,然后stack.peek().append()各种操作 一个栈存string, 一个栈存number, 维护一个指针numStart指向数字的开始 1. 遇到数字啥也不做 2. 遇到char: stack.peek().append(c 阅读全文
posted @ 2016-12-01 05:07 neverlandly 阅读(474) 评论(0) 推荐(0)
Leetcode: Perfect Rectangle
摘要: Refer to https://discuss.leetcode.com/topic/56052/really-easy-understanding-solution-o-n-java and https://discuss.leetcode.com/topic/55923/o-n-solutio 阅读全文
posted @ 2016-12-01 02:12 neverlandly 阅读(563) 评论(0) 推荐(0)
2016年11月30日
Leetcode: Random Pick Index
摘要: Three types of answer: Map Solution, O(N) memory, O(N) init, O(1) pick. Like @dettier's Reservoir Sampling. O(1) init, O(1) memory, but O(N) to pick. 阅读全文
posted @ 2016-11-30 12:23 neverlandly 阅读(410) 评论(0) 推荐(0)
Leetcode: Sum of Left Leaves
摘要: Recursion: 是不是left子数完全由bottom往上第二层决定,如果是left子树且是叶子节点,那么就是left leaves, parent得告诉child是不是在left子树 BFS: 阅读全文
posted @ 2016-11-30 11:45 neverlandly 阅读(370) 评论(0) 推荐(0)
Leetcode: Is Subsequence
摘要: Basic Solution: DP, O(mn) time, O(m) space, m is the size of s, n is the size of t Greedy Solution: O(n) time, O(1) space Follow Up: The best solution 阅读全文
posted @ 2016-11-30 11:09 neverlandly 阅读(1189) 评论(0) 推荐(0)
Leetcode: Elimination Game
摘要: refer to https://discuss.leetcode.com/topic/59293/java-easiest-solution-o-logn-with-explanation Time Complexity: O(log n) update and record head in ea 阅读全文
posted @ 2016-11-30 06:52 neverlandly 阅读(360) 评论(0) 推荐(0)
Leetcode: Find the Difference
摘要: O(N)time, O(1) space 阅读全文
posted @ 2016-11-30 05:40 neverlandly 阅读(251) 评论(0) 推荐(0)
Leetcode: Longest Absolute File Path
摘要: Time Complexity: O(N) The depth of the directory/file is calculated by counting how many "\t"s are there.The time complexity is O(n) because each subs 阅读全文
posted @ 2016-11-30 05:19 neverlandly 阅读(362) 评论(0) 推荐(0)
Leetcode: Mini Parser
摘要: 有括号这种一般要用stack, stack top 就是当前着眼的那一个NestedInteger, 可以对其添加新的元素。 注意47行判断很关键,顺带处理了 "[]," 括号后面是逗号的情况 阅读全文
posted @ 2016-11-30 02:28 neverlandly 阅读(379) 评论(0) 推荐(0)
2016年11月29日
Leetcode: First Unique Character in a String
摘要: Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1. Examples: s = "leetcode" return 0. s = "loveleetcode", return 2. Note: You may a... 阅读全文
posted @ 2016-11-29 12:24 neverlandly 阅读(312) 评论(0) 推荐(0)
Leetcode: Lexicographical Numbers
摘要: Solution 1: Solution 2: O(N) time, O(1) space The basic idea is to find the next number to add.Take 45 for example: if the current number is 45, the n 阅读全文
posted @ 2016-11-29 11:59 neverlandly 阅读(334) 评论(0) 推荐(0)
Leetcode: Shuffle an Array
摘要: Random random = new Random(); random.nextInt(int i); 阅读全文
posted @ 2016-11-29 10:53 neverlandly 阅读(564) 评论(0) 推荐(0)
Leetcode: Ransom Note
摘要: using one array 阅读全文
posted @ 2016-11-29 06:41 neverlandly 阅读(301) 评论(0) 推荐(0)
Leetcode: Linked List Random Node
摘要: Solution 1: Reservior sampling: (wiki introduction) Reservoir sampling is a family of randomized algorithms for randomly choosing a sample of k items 阅读全文
posted @ 2016-11-29 06:19 neverlandly 阅读(515) 评论(0) 推荐(0)
上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 21 下一页
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3