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

随笔分类 -  Leetcode

上一页 1 ··· 12 13 14 15 16 17 18 19 20 ··· 32 下一页
Leetcode: Integer Break

摘要:O(N^2)解法: DP dp[i] represent the maximum product of breaking up integer i O(N)解法: the best factor is 3. we keep breaking n into 3's until n gets small 阅读全文
posted @ 2016-11-24 04:57 neverlandly 阅读(356) 评论(0) 推荐(0)
Leetcode: Flatten Nested List Iterator

摘要:非常精巧地使用stack。push all the nestedList into the stack from back to front,so when we pop the stack, it returns the very first element 执行hasNext()的时候,如果pe 阅读全文
posted @ 2016-11-24 01:29 neverlandly 阅读(424) 评论(0) 推荐(0)
Leetcode: Reverse String

摘要:After the API changes 注意没有append(0, s.charAt(i)), 是sb.insert(0, charAt(i)); 阅读全文
posted @ 2016-11-23 12:20 neverlandly 阅读(303) 评论(0) 推荐(0)
Leetcode: Power of Four

摘要:it's easy to find that power of 4 numbers have those 3 common features. First,greater than 0. Second,only have one '1' bit in their binary notation,so 阅读全文
posted @ 2016-11-23 11:48 neverlandly 阅读(245) 评论(0) 推荐(0)
Leetcode: House Robber III

摘要:https://discuss.leetcode.com/topic/39834/step-by-step-tackling-of-the-problem rob(root) which will return the maximum amount of money that we can rob 阅读全文
posted @ 2016-11-23 11:17 neverlandly 阅读(326) 评论(0) 推荐(0)
Leetcode: Counting Bits

摘要:Hint: 阅读全文
posted @ 2016-11-23 07:36 neverlandly 阅读(359) 评论(0) 推荐(0)
Leetcode: Palindrome Pairs

摘要:Naive Solution: Time: O(n^2*k) with n the total number of words in the "words" array and k the average length of each word: check each combination see 阅读全文
posted @ 2016-11-23 06:29 neverlandly 阅读(361) 评论(0) 推荐(0)
Leetcode: Self Crossing

摘要:4th line may cross with 1st line, and so on: 5th with 2nd, ...etc 5th line may cross with 1st line, and so on: 6th with 2nd, ...etc 6th line also may 阅读全文
posted @ 2016-11-23 03:51 neverlandly 阅读(381) 评论(0) 推荐(0)
Leetcode: Increasing Triplet Subsequence

摘要:Naive Solution: use DP, Time O(N^2), Space O(N) dp[i] represents the length of longest increasing subsequence till i including element i in nums array 阅读全文
posted @ 2016-11-23 01:42 neverlandly 阅读(363) 评论(0) 推荐(0)
Leetcode: Reconstruct Itinerary

摘要:refer to Recursion https://leetcode.com/discuss/84702/share-my-solution and Iteration https://leetcode.com/discuss/84706/share-solution-java-greedy-st 阅读全文
posted @ 2016-02-08 12:29 neverlandly 阅读(4094) 评论(0) 推荐(0)
Leetcode: Verify Preorder Serialization of a Binary Tree

摘要:One way to serialize a binary tree is to use pre-oder traversal. When we encounter a non-null node, we record the node's value. If it is a null node, 阅读全文
posted @ 2016-02-01 07:31 neverlandly 阅读(1171) 评论(0) 推荐(0)
Leetcode: Patching Array

摘要:Given a sorted positive integer array nums and an integer n, add/patch elements to the array such that any number in range [1, n] inclusive can be for 阅读全文
posted @ 2016-01-28 02:07 neverlandly 阅读(710) 评论(0) 推荐(0)
Leetcode: Longest Increasing Path in a Matrix

摘要:DFS + DP: use a two dimensional matrix dp[i][j] to store the length of the longest increasing path starting at matrix[i][j] transferring function is: 阅读全文
posted @ 2016-01-25 10:42 neverlandly 阅读(1528) 评论(0) 推荐(0)
Leetcode: Range Sum Query 2D - Mutable && Summary: Binary Indexed Tree

摘要:参考:https://leetcode.com/discuss/72685/share-my-java-2-d-binary-indexed-tree-solution Build binary indexed tree takes : O(mn*logm*logn) time, both upda 阅读全文
posted @ 2016-01-18 05:44 neverlandly 阅读(1502) 评论(0) 推荐(0)
Leetcode: Odd Even Linked List

摘要:Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the... 阅读全文
posted @ 2016-01-18 03:59 neverlandly 阅读(1742) 评论(0) 推荐(0)
Leetcode: Count of Range Sum

摘要:Given an integer array nums, return the number of range sums that lie in [lower, upper] inclusive. Range sum S(i, j) is defined as the sum of the elem 阅读全文
posted @ 2016-01-18 03:49 neverlandly 阅读(4066) 评论(0) 推荐(0)
Leetcode: Power of Three

摘要:Given an integer, write a function to determine if it is a power of three. Follow up: Could you do it without using any loop / recursion? Recursion: 1 阅读全文
posted @ 2016-01-09 04:32 neverlandly 阅读(5857) 评论(0) 推荐(0)
Leetcode: Maximum Size Subarray Sum Equals k

摘要:Given an array nums and a target value k, find the maximum length of a subarray that sums to k. If there isn't one, return 0 instead.Example 1:Given n... 阅读全文
posted @ 2016-01-06 04:20 neverlandly 阅读(7425) 评论(0) 推荐(0)
Leetcode: Range Sum Query - Mutable && Summary: Segment Tree

摘要:Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.The update(i, val) function modifies nums by upda... 阅读全文
posted @ 2016-01-02 13:48 neverlandly 阅读(493) 评论(0) 推荐(0)
Leetcode: Create Maximum Number

摘要:Given two arrays of length m and n with digits 0-9 representing two numbers. Create the maximum number of length k 0 && n-i-1>=count-j && res[j-1]arr2... 阅读全文
posted @ 2016-01-02 10:17 neverlandly 阅读(2969) 评论(0) 推荐(0)

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