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

随笔分类 -  Leetcode

上一页 1 ··· 18 19 20 21 22 23 24 25 26 ··· 32 下一页
Leetcode: Word Search II

摘要:如果跟Word Search做法一样,还按照DFS回溯的方法,逐个检查每个word是否在board里,显然效率是比较低的。我们可以利用Trie数据结构,也就是前缀树。然后dfs时,如果当前形成的单词不在Trie里,就没必要继续dfs下去了。如果当前字符串在trie里,就说明board可以形成这个wo 阅读全文
posted @ 2015-12-18 03:22 neverlandly 阅读(533) 评论(0) 推荐(0)
Leetcode: Rectangle Area

摘要:Find the total area covered by two rectilinear rectangles in a 2D plane.Each rectangle is defined by its bottom left corner and top right corner as sh... 阅读全文
posted @ 2015-12-18 00:48 neverlandly 阅读(324) 评论(0) 推荐(0)
Leetcode: Shortest Palindrome

摘要:本题最简单的思路是从后往前判断子串是否是回文串,然后把后面的弄到前面即可,不过这样仅仅能擦边通过测试 Brute Force: O(N^2), space O(1) DP: O(N^2), space O(N^2) KMP介绍:http://kb.cnblogs.com/page/176818/ 实 阅读全文
posted @ 2015-12-17 14:43 neverlandly 阅读(300) 评论(0) 推荐(0)
Leetcode: Combination Sum III

摘要:ind all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a... 阅读全文
posted @ 2015-12-17 12:56 neverlandly 阅读(262) 评论(0) 推荐(0)
Leetcode: House Robber II

摘要:Analysis: if the last one is not robbed, then you are free to choose whether to rob the first one. you can break the circle by assuming the first hous 阅读全文
posted @ 2015-12-17 12:20 neverlandly 阅读(337) 评论(0) 推荐(0)
Leetcode: Contains Duplicate II

摘要:Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the ... 阅读全文
posted @ 2015-12-17 07:44 neverlandly 阅读(198) 评论(0) 推荐(0)
Leetcode: Kth Largest Element in an Array

摘要:Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.For examp... 阅读全文
posted @ 2015-12-17 07:30 neverlandly 阅读(347) 评论(0) 推荐(0)
Leetcode: Contains Duplicate

摘要:Use HashSet: 阅读全文
posted @ 2015-12-17 07:01 neverlandly 阅读(198) 评论(0) 推荐(0)
Leetcode: Minimum Size Subarray Sum

摘要:Haven't think about the O(nlogn) solution. O(n) solution is to maintain a window My solution: shrink as much as possible while maintaining the window 阅读全文
posted @ 2015-12-17 06:52 neverlandly 阅读(289) 评论(0) 推荐(0)
Leetcode: Add and Search Word - Data structure design

摘要:方法1:brute force: search function compares each word with the pattern, time complexity: O(nk), n is number of words in dictionary, k is averge length 方 阅读全文
posted @ 2015-12-17 06:46 neverlandly 阅读(619) 评论(0) 推荐(0)
Leetcode: Implement Trie (Prefix Tree) && Summary: Trie

摘要:参考百度百科:Trie树 a trie, also called digital tree and sometimes radix tree or prefix tree (as they can be searched by prefixes) The time complexity to ins 阅读全文
posted @ 2015-12-16 13:45 neverlandly 阅读(529) 评论(0) 推荐(0)
Leetcode: Course Schedule II

摘要:There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have prerequisites, for example to take course 0 you have t 阅读全文
posted @ 2015-12-16 12:25 neverlandly 阅读(324) 评论(0) 推荐(0)
Leetcode: Course Schedule

摘要:The hint provided by leetcode is: Hints: BFS: 典型的拓扑排序。原理也很简单,在一个有向图中,每次找到一个没有前驱节点的节点(也就是入度为0的节点),然后把它指向其他节点的边都去掉,重复这个过程(BFS),直到所有节点已被找到,或者没有符合条件的节点(如果 阅读全文
posted @ 2015-12-16 11:18 neverlandly 阅读(311) 评论(0) 推荐(0)
Leetcode: Isomorphic Strings

摘要:Best: O(N) time, constant space 复杂度 时间 O(N) 空间 O(N) 思路 用一个哈希表记录字符串s中字母到字符串t中字母的映射关系,一个集合记录已经映射过的字母。或者用两个哈希表记录双向的映射关系。这里不能只用一个哈希表,因为要排除egg->ddd这种多对一的映射 阅读全文
posted @ 2015-12-15 11:46 neverlandly 阅读(333) 评论(0) 推荐(0)
Leetcode: Reverse Linked List

摘要:基本迭代 Time: O(N), Space: O(1) 基本递归 Time: O(N), Space: O(N)递归栈大小 阅读全文
posted @ 2015-12-15 11:15 neverlandly 阅读(267) 评论(0) 推荐(0)
Leetcode: Count Primes

摘要:Count the number of prime numbers less than a non-negative number, n.Algorithm: The sieve of Eratosthenes,Referring to Summary: Primes0 and 1 are not ... 阅读全文
posted @ 2015-12-15 03:09 neverlandly 阅读(275) 评论(0) 推荐(0)
Leetcode: Remove Linked List Elements

摘要:set Dummy node 这题有个重要的follow up,就是在一个环里怎么删除节点: 参考:http://www.cnblogs.com/EdwardLiu/p/5975748.html 阅读全文
posted @ 2015-12-15 02:24 neverlandly 阅读(268) 评论(0) 推荐(0)
Leetcode: Bitwise AND of Numbers Range

摘要:Given a range [m, n] where 0 maxRange) continue; 9 int mi = (m>>i) & 1;10 int ni = (n>>i) & 1;11 if (mi == 1 && n... 阅读全文
posted @ 2015-12-15 02:14 neverlandly 阅读(217) 评论(0) 推荐(0)
Leetcode: Happy Number

摘要:Write an algorithm to determine if a number is "happy". A happy number is a number defined by the following process: Starting with any positive intege 阅读全文
posted @ 2015-12-15 00:53 neverlandly 阅读(315) 评论(0) 推荐(0)
Leetcode: House Robber

摘要:This particular problem and most of others can be approached using the following sequence: https://leetcode.com/problems/house-robber/discuss/156523/F 阅读全文
posted @ 2015-04-12 03:36 neverlandly 阅读(589) 评论(0) 推荐(0)

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