
LeetCode
文章平均质量分 55
低调小一
Ubuntu重度患者,曾经的服务器开发工程师,如今正在深入学习到Android Framework
展开
-
[LeetCode]Number of Digit One,解题报告
题目Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n.For example: Given n = 13, Return 6, because digit 1 occurred in the following n原创 2015-07-30 12:34:10 · 3095 阅读 · 0 评论 -
[LeetCode]Word Break,解题报告
目录目录前言题目DFS动态规划前言过完年回来状态一直就是懒懒散散的,之前想写的年终总结也一直再拖沓。所以,从今天起找回之前的状态,每日的工作计划没完成就不能休息。今天的任务中有两道LeetCode题目,其中一道动态规划的题目稍微难一点,这里记录一下解题过程。题目Given a string s and a dictionary of words di原创 2015-03-10 09:38:53 · 3456 阅读 · 0 评论 -
[LeetCode]Surrounded Regions,解题报告
目录目录前言题目思路1DFS思路2BFS前言最近这两天为了解决Android Rom适配一个底层的问题,天天熬夜到2点,导致原定了LeetCode刷题计划都受到了影响。昨晚终于熬夜搞定,补充一道LeetCode解题报告。题目Given a 2D board containing ‘X’ and ‘O’, capture all regions sur原创 2015-03-20 20:11:02 · 4022 阅读 · 0 评论 -
[LeetCode]Min Stack,解题报告
目录目录题目思路1AC代码缺陷思路2AC代码题目 Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. push(x) – Push element x onto stack. pop() – Removes the ele原创 2015-03-02 12:17:31 · 1856 阅读 · 0 评论 -
[LeetCode]Word Ladder,解题报告
目录目录题目题目Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that:Only one letter can be changed at a time原创 2015-03-25 11:30:43 · 4992 阅读 · 0 评论 -
[LeetCode]Binary Search Tree Iterator,解题报告
题目 LeetCode题目如下:mplement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Calling next() will return the next smallest number in the原创 2015-02-09 21:11:40 · 2312 阅读 · 1 评论 -
LRU算法&&LeetCode解题报告
题目Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set.get(key) - Get the value (will always be positive) of the key原创 2014-06-23 00:56:51 · 4406 阅读 · 1 评论 -
[LeetCode]Find Minimum in Rotated Sorted Array,解题报告
前言 今天来杭州参加百阿培训,住在4星级的旅馆,加上快一月底了我都没有几篇博客产出,所以准备开始水LeetCode题目了,这里介绍一个二分查找的应用。题目Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become原创 2015-02-03 21:58:31 · 1442 阅读 · 0 评论 -
[LeetCode]3Sum,解题报告
题目Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:Elements in a triplet (a,b,c)原创 2014-06-13 23:42:52 · 3327 阅读 · 2 评论 -
[LeetCode]Distinct Subsequences,解题报告
题目Given a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string by deleting some (can be原创 2014-06-05 16:45:49 · 2054 阅读 · 0 评论 -
[LeetCode]Palindrome Number,解题报告
题目Determine whether an integer is a palindrome. Do this without extra space.click to show spoilers.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of con原创 2013-12-21 23:46:46 · 1750 阅读 · 0 评论 -
[LeetCode]Trapping Rain Water,解题报告
前言在LeetCode上又碰到了一道笔试原题,充分说明提前的准备对应届生找工作有多大的作用,年终总结我会具体写一下自己找工作的准备历程,耗时将近半年时间题目Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much w原创 2014-01-02 11:11:59 · 10155 阅读 · 2 评论 -
[LeetCode]Spiral Matrix,解题报告
前言新年第一篇博客先来一个解题报告吧,主要也是自己比较懒,跨年夜女友发烧各种照顾了,没来得及写年终总结,这篇解题报告也是我在做题过程中有些心得体会,跟大家分享!切忌心不静做题切忌杂乱无章,做题的时候想一下子处理所有特殊情况,结果越做约错在这里,先祝福各位看我博客的同学元旦快乐,万事如意题目Given a matrix of m x n ele原创 2014-01-01 12:13:00 · 2602 阅读 · 2 评论 -
[LeetCode]Longest Valid Parentheses, 解题报告
题目Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", the longest valid parentheses substring is "()",原创 2014-05-12 10:59:06 · 1621 阅读 · 0 评论 -
[LeetCode]Binary Tree Maximum Path Sum, 解题报告
题目Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary tree,原创 2014-05-10 21:22:16 · 1836 阅读 · 0 评论 -
[LeetCode]Repeated DNA Sequences,解题报告
目录目录前言题目Native思路二进制思路AC前言最近在LeetCode上能一次AC的概率越来越低了,我这里也是把每次不能一次AC的题目记录下来,把解题思路分享给大家。题目All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: “ACGAATTCCG”. When原创 2015-03-14 12:09:42 · 4601 阅读 · 0 评论 -
[LeetCode]Largest Number, 解题报告
目录目录题目思路AC代码题目 Given a list of non negative integers, arrange them such that they form the largest number. For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330. Not原创 2015-04-05 12:30:39 · 4556 阅读 · 0 评论 -
[LeetCode]Product of Array Except Self,解题报告
题目Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Solve it without division and in O(n).For原创 2015-07-17 10:20:32 · 14076 阅读 · 1 评论 -
[LeetCode]Container With Most Water, 解题报告
前言难怪LeetCode OJ在找工作时被很多人推荐,发现了这道最大蓄水题目就是美团的笔试最后一道题,当时我霸笔只有着一道题目没有答出来,因此也就没有获得面试机会,可惜了题目Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n v原创 2013-12-10 19:47:10 · 21886 阅读 · 8 评论 -
[LeetCode]Add and Search Word - Data structure design,解题报告
目录目录思路思路AC代码思路Design a data structure that supports the following two operations: void addWord(word) bool search(word)search(word) can search a literal word or a regular expression string cont原创 2015-05-18 16:02:31 · 5849 阅读 · 0 评论 -
[LeetCode]Implement Trie(Prefix Tree),解题报告
目录目录概述Trie树基本实现定义Trie树节点添加操作查询word是否在Trie树中AC完整代码概述Trie树,又称为字典树、单词查找树或者前缀树,是一种用于快速检索的多叉数结构。例如,英文字母的字典树是26叉数,数字的字典树是10叉树。 Trie树的基本性质有三点,归纳为:根节点不包含字符,根节点外每一个节点都只包含一个字符。从根节点到某一节点,路径上经过的字符连接起来,为该节原创 2015-05-15 14:12:30 · 6240 阅读 · 1 评论 -
[LeetCode]Course Schedule,解题报告
题目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 to first take course 1, which is expressed as a pai原创 2015-05-11 15:37:37 · 4984 阅读 · 0 评论 -
[LeetCode]Nth Highest Salary,解题报告
题目Write a SQL query to get the nth highest salary from the Employee table. Id Salary 1 100 2 200 3 300For example, given the above Employee table, the nth highest salary where n = 2 is原创 2015-04-28 11:40:12 · 6366 阅读 · 0 评论 -
[LeetCode]Department Highest Salary,解题报告
题目The Employee table holds all employees. Every employee has an Id, a salary, and there is also a column for the department Id. Id Name Salary DepartmentId 1 Joe 70000 1 2 Henry 80原创 2015-04-25 11:22:32 · 4800 阅读 · 0 评论 -
[LeetCode]Rank Scores,解题报告
题目Write a SQL query to rank scores. If there is a tie between two scores, both should have the same ranking. Note that after a tie, the next ranking number should be the next consecutive integer value.原创 2015-04-21 17:19:35 · 5732 阅读 · 0 评论 -
[LeetCode]DeleteDuplicateEmails,解题报告
题目SQL query to delete all duplicate email entries in a table named Person, keeping only unique emails based on its smallest Id. Id Email 1 john@example.com 2 bob@example.com 3 john@examp原创 2015-04-17 10:29:51 · 3941 阅读 · 0 评论 -
[LeetCode]Number of Islands,解题报告
目录目录前言题目思路AC代码我的疑问前言利用晚上11点之后的时间刷刷LeetCode也是我的一种休闲方式。不过水这篇博客是因为这道简单的BFS题目我竟然用了13次才AC,最后AC还是因为我参考了别人的答案,稍后我会说一下我对这道题的疑惑。先贴出这道题目我艰难的AC过程: 中间那次313ms的ac答案是我直接把别人的AC代码贴上,因为当时我怀疑这道题目答案是否出了问题。题目Given a原创 2015-04-15 23:43:15 · 7340 阅读 · 1 评论 -
[LeetCode]Duplicate Emails,解题报告
目录目录题目解题思路AC SQL题目Write a SQL query to find all duplicate emails in a table named Person. Id Email 1 a@b.com 2 c@d.com 3 a@b.comFor example, your query should return the following fo原创 2015-04-14 14:14:13 · 4662 阅读 · 0 评论 -
[LeetCode]Rising Temperature,解题报告
目录目录题目思路AC SQL题目Given a Weather table, write a SQL query to find all dates’ Ids with higher temperature compared to its previous (yesterday’s) dates. Id(INT) Date(DATE) Temperature(INT) 1 2原创 2015-04-13 18:14:47 · 8326 阅读 · 0 评论 -
[LeetCode]Employees Earning More Than Their Managers,解题报告
目录目录题目思路AC SQL题目The Employee table holds all employees including their managers. Every employee has an Id, and there is also a column for the manager Id. Id Name Salary ManagerId 1 Joe原创 2015-04-13 19:42:03 · 4842 阅读 · 0 评论 -
[LeetCode]Largest Rectangle in Histgram,解题报告
目录目录题目思路一思路二题目Given n non-negative integers representing the histogram’s bar height where the width of each bar is 1, find the area of largest rectangle in the histogram. Above is a histogram where原创 2015-04-23 11:01:43 · 3924 阅读 · 0 评论 -
[LeetCode]Restore IP Addresses, 解题报告
前言好久没有写关于ACM的博客了,确实是最近太忙,也怪我之前涉猎太少,i原创 2014-04-07 23:26:56 · 3198 阅读 · 0 评论 -
[LeetCode]Merge Intervals, 解题报告
题目Given a collection of intervals, merge all overlapping intervals.For example,Given [1,3],[2,6],[8,10],[15,18],return [1,6],[8,10],[15,18].解题思路题目不难,注意几点即可:1. Java的Comparator原创 2014-04-20 18:06:43 · 1726 阅读 · 0 评论 -
[LeetCode]Candy, 解题报告
前言回学校写论文差不多快一周的时间了,原创 2014-05-05 16:49:03 · 2155 阅读 · 0 评论 -
[LeetCode]Integer to Roman,解题报告
前言这周末加上这星期的5天都需要帮导师做一个北邮烂尾的项目,很辛苦,不过知遇之恩确实太大,无以为报,只能竭心尽力无奈项目是用svn版本库控制,github的提交记录又多了一天空白,看着很不爽,哪天我不在github上提交代码,必然在svn上提交,嘿嘿题目Given an integer, convert it to a roman numeral.Input原创 2013-12-23 23:26:34 · 2123 阅读 · 1 评论 -
[LeetCode]Populating Next Right Pointers in Each Node II, 解题报告
前言今天上午从9点半开始就做了这么一道题目,还是挺有意思的,这里记录一下题目Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution st原创 2013-12-19 11:17:47 · 8544 阅读 · 2 评论 -
字符串组合算法
全组合例如给定字符串“abc”,全组合意思从中去0个元素,1个元素,一直到n个元素,介绍二进制做法。以字符串“abc”为例:000 NULL001 c010 b011 bc100 a101 ac110 ab111 abc思路出来了,代码也比较好写,分享一下我的代码:/** * Write a method that returns原创 2013-09-25 15:56:21 · 3377 阅读 · 5 评论 -
[LeetCode]Unique Binary Search Trees, 解题报告
前言今天准备把LeetCode上AC Rates在30%以上的题目全部收尾,这道题目也是我在这个AC Rate上遇到的感觉最麻烦的一道题目,分享一下自己的解题思路而且这道题目AC Rate竟然这么高题目Given n, how many structurally unique BST's (binary search trees) that原创 2013-12-05 11:11:18 · 4444 阅读 · 2 评论 -
Java集合LinkedList模拟队列
前言下午写LeetCode期间需要使用广度优先搜索算法,配合队列这种数据结构,队列数据结构的特性可以参考我之前的文章:队列的学习在java里使用队列可以用LinkedList集合进行模拟方法使用LinkedList集合,并使用其中的addLast、removeFirst、isEmpty等API集体模拟队列操作入队列void addLast(E原创 2013-12-02 16:39:27 · 4207 阅读 · 0 评论 -
[LeetCode],Pascal's Triangle, 解题报告
题目Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return思路典型的杨辉三角题目,说一下构造杨辉三角的思路:每个数字等于上一行的左右两个数字之和。可用此性质写出整个杨辉三角。即第n+1行的第原创 2013-12-04 00:41:13 · 2057 阅读 · 1 评论