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

随笔分类 -  Leetcode

上一页 1 ··· 16 17 18 19 20 21 22 23 24 ··· 32 下一页
Leetcode: 3Sum Smaller

摘要:Given an array of n integers nums and a target, find the number of index triplets i, j, k with 0 =2; i--) { 6 //if (i!=nums.length-1 && (n... 阅读全文
posted @ 2015-12-23 04:47 neverlandly 阅读(322) 评论(0) 推荐(0)
Leetcode: Factor Combinations

摘要:Numbers can be regarded as product of its factors. For example, 8 = 2 x 2 x 2; = 2 x 4. Write a function that takes an integer n and return all possib 阅读全文
posted @ 2015-12-23 02:33 neverlandly 阅读(475) 评论(0) 推荐(0)
Leetcode: Different Ways to Add Parentheses

摘要:用到了Divide and Conquer, 跟 Leetcode: Unique Binary Search Trees II 很像 在input string里遍历各个operator, 依据每个operator分成左右子串,左右子串做递归返回所有可能的results,然后全排列。 注意很巧妙的 阅读全文
posted @ 2015-12-23 00:43 neverlandly 阅读(332) 评论(0) 推荐(0)
Leetcode: Add Digits

摘要:我的方法:注意最方便的获取一个数每一位的方法,是把它转化为String先,通过String.valueOf(int c) O(1): http://my.oschina.net/Tsybius2014/blog/497645 另一个方法比较简单,可以举例说明一下。假设输入的数字是一个5位数字num, 阅读全文
posted @ 2015-12-22 13:28 neverlandly 阅读(241) 评论(0) 推荐(0)
Leetcode: Binary Tree Paths

摘要:Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths are:["1->... 阅读全文
posted @ 2015-12-22 12:44 neverlandly 阅读(275) 评论(0) 推荐(0)
Leetcode: Verify Preorder Sequence in Binary Search Tree

摘要:4 / \ 2 6 / \ / \ 1 3 5 7 如图所示BST, preorder结果是 4 2 1 3 6 5 7 4是root, 213是左子树,657是右子树 idea就是右子树不能再出现比root小的数,一旦出现,return false. 这样一层一层recursion, 直到子树只剩 阅读全文
posted @ 2015-12-22 11:16 neverlandly 阅读(293) 评论(0) 推荐(0)
Leetcode: Meeting Rooms II

摘要:Like the previous one Meeting Room, still need to sort the intervals using a comparator. We need to simulate the process to know the maximum number of 阅读全文
posted @ 2015-12-22 09:19 neverlandly 阅读(949) 评论(0) 推荐(0)
Leetcode: Meeting Rooms

摘要:Interval as an array: Previous interval as an object: Implement a Comparator<Interval> Syntax: don't forget the public sign when defining a function 阅读全文
posted @ 2015-12-22 08:32 neverlandly 阅读(302) 评论(0) 推荐(0)
Leetcode: Flatten 2D Vector

摘要:Implement an iterator to flatten a 2d vector.For example,Given 2d vector =[ [1,2], [3], [4,5,6]]By calling next repeatedly until hasNext returns fa... 阅读全文
posted @ 2015-12-22 08:13 neverlandly 阅读(281) 评论(0) 推荐(0)
Leetcode: Count Univalue Subtrees

摘要:Given a binary tree, count the number of uni-value subtrees.A Uni-value subtree means all nodes of the subtree have the same value.For example:Given b... 阅读全文
posted @ 2015-12-22 07:22 neverlandly 阅读(1746) 评论(0) 推荐(0)
Leetcode: Group Shifted Strings

摘要:Given a string, we can "shift" each of its letter to its successive letter, for example: "abc" -> "bcd". We can keep "shifting" which forms the sequen... 阅读全文
posted @ 2015-12-22 02:04 neverlandly 阅读(443) 评论(0) 推荐(0)
Leetcode: Paint House

摘要:The same with F面经 Better Solution: O(N) time, O(1) space 阅读全文
posted @ 2015-12-21 13:34 neverlandly 阅读(336) 评论(0) 推荐(0)
Leetcode: Strobogrammatic Number III

摘要:A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down).Write a function to count the total strobogr... 阅读全文
posted @ 2015-12-21 12:53 neverlandly 阅读(340) 评论(0) 推荐(0)
Leetcode: Strobogrammatic Number II

摘要:Watch out for cornor case: when n = 2, there shouldn't be "00" returned. but when n = 4, which uses n =2 as recursion base, "1001" is an answer 阅读全文
posted @ 2015-12-21 09:30 neverlandly 阅读(310) 评论(0) 推荐(0)
Leetcode: Strobogrammatic Number

摘要:Related to confusing number O(N) time and O(N) space O(N) time and O(1) space, use two pointers 阅读全文
posted @ 2015-12-21 07:11 neverlandly 阅读(292) 评论(0) 推荐(0)
Leetcode: Shortest Word Distance III

摘要:This is a follow up of Shortest Word Distance. The only difference is now word1 could be the same as word2.Given a list of words and two words word1 a... 阅读全文
posted @ 2015-12-21 06:40 neverlandly 阅读(281) 评论(0) 推荐(0)
Leetcode: Shortest Word Distance II

摘要:This is a follow up of Shortest Word Distance. The only difference is now you are given the list of words and your method will be called repeatedly ma... 阅读全文
posted @ 2015-12-21 04:34 neverlandly 阅读(322) 评论(0) 推荐(0)
Leetcode: Shortest Word Distance

摘要:双指针法:time O(N), space O(1) 一个指针指向word1上次出现的位置,一个指针指向word2上次出现的位置。因为两个单词如果比较接近的话,肯定是相邻的word1和word2的位置之差,所以我们只要每次得到一个新位置和另一个单词的位置比较一下就行了。 阅读全文
posted @ 2015-12-21 00:57 neverlandly 阅读(305) 评论(0) 推荐(0)
Leetcode: Valid Anagram

摘要:还不知道Unicode 该怎么做 只有lowercase alphabets的做法无外乎sort, hashmap, array, bitmap之类的 Better: Unicode Follow up In Java, a Unicode could be represented by a sin 阅读全文
posted @ 2015-12-20 13:24 neverlandly 阅读(331) 评论(0) 推荐(0)
Leetcode: Search a 2D Matrix II

摘要:Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted i 阅读全文
posted @ 2015-12-20 12:42 neverlandly 阅读(247) 评论(0) 推荐(0)

上一页 1 ··· 16 17 18 19 20 21 22 23 24 ··· 32 下一页
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3