【Todo】所有Locked的题目的分析解答

下面这个链接有比较全的leetcode题目包括锁的

http://www.cnblogs.com/grandyang/p/4606334.html

https://leetcode.com/problems/binary-tree-upside-down/

http://blog.csdn.net/xudli/article/details/42362441

https://leetcode.com/problems/read-n-characters-given-read4/

http://blog.csdn.net/xudli/article/details/42458865

https://leetcode.com/problems/read-n-characters-given-read4-ii-call-multiple-times/

http://blog.csdn.net/xudli/article/details/43225571

https://leetcode.com/problems/longest-substring-with-at-most-two-distinct-characters/

http://blog.csdn.net/xudli/article/details/43222593

https://leetcode.com/problems/one-edit-distance/

http://blog.csdn.net/xudli/article/details/42340867

https://leetcode.com/problems/missing-ranges/

http://blog.csdn.net/yangliuy/article/details/46502541

https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/

http://blog.csdn.net/xudli/article/details/42290269

https://leetcode.com/problems/two-sum-iii-data-structure-design/

http://blog.csdn.net/xudli/article/details/42290251

https://leetcode.com/problems/reverse-words-in-a-string-ii/

http://www.cnblogs.com/dolphin0520/p/3700019.html

https://leetcode.com/problems/shortest-word-distance/

http://blog.csdn.net/xudli/article/details/48766955

https://leetcode.com/problems/shortest-word-distance-ii/

http://nb4799.neu.edu/wordpress/?p=1028

https://leetcode.com/problems/shortest-word-distance-iii/

http://www.cnblogs.com/easonliu/p/4784826.html

https://leetcode.com/problems/strobogrammatic-number/

http://www.cnblogs.com/grandyang/p/5196960.html

http://www.tangjikai.com/algorithms/leetcode-246-strobogrammatic-number

https://leetcode.com/problems/strobogrammatic-number-ii/

http://www.cnblogs.com/grandyang/p/5200919.html

http://www.cnblogs.com/airwindow/p/4804054.html

https://leetcode.com/problems/strobogrammatic-number-iii/

http://www.cnblogs.com/grandyang/p/5203228.html

https://leetcode.com/problems/group-shifted-strings/

http://www.cnblogs.com/airwindow/p/4806168.html

https://leetcode.com/problems/count-univalue-subtrees/

http://blog.csdn.net/pointbreak1/article/details/48998407

https://leetcode.com/problems/flatten-2d-vector/

http://blog.csdn.net/pointbreak1/article/details/48823513

https://leetcode.com/problems/meeting-rooms/

http://blog.csdn.net/sbitswc/article/details/49068503

https://leetcode.com/problems/meeting-rooms/

方法很好

http://blog.csdn.net/sbitswc/article/details/49068625

https://leetcode.com/problems/factor-combinations/

方法不错

http://www.cnblogs.com/airwindow/p/4822572.html

https://leetcode.com/problems/verify-preorder-sequence-in-binary-search-tree/

http://www.meetqun.com/thread-10674-1-1.html (递归)

http://www.thinksaas.cn/topics/0/397/397305.html (非递归,constant space)

https://leetcode.com/problems/paint-house/

http://www.cnblogs.com/easonliu/p/4784858.html

https://leetcode.com/problems/3sum-smaller/

好题

http://www.cnblogs.com/airwindow/p/4802521.html

https://leetcode.com/problems/graph-valid-tree/

https://segmentfault.com/a/1190000003791051

http://blog.csdn.net/dm_vincent/article/details/7655764 (并查集)

https://leetcode.com/problems/paint-house-ii/

http://www.cnblogs.com/easonliu/p/4784858.html

https://leetcode.com/problems/palindrome-permutation/

http://www.cnblogs.com/anne-vista/p/4831003.html (一样的,用map或者set)

https://leetcode.com/problems/palindrome-permutation-ii/

http://www.cnblogs.com/airwindow/p/4806012.html

https://leetcode.com/problems/alien-dictionary/

好,DFS(toposort)or BFS(based on indegree)

http://www.cnblogs.com/jcliBlogger/p/4758761.html

https://leetcode.com/problems/closest-binary-search-tree-value/

http://www.cnblogs.com/Dylan-Java-NYC/p/5204357.html

https://leetcode.com/problems/encode-and-decode-strings/

利用长度,巧妙

http://www.cnblogs.com/easonliu/p/4784912.html

https://leetcode.com/problems/closest-binary-search-tree-value-ii/

利用堆

http://blog.csdn.net/xudli/article/details/48752907

https://leetcode.com/problems/paint-fence/

题目见

http://www.cnblogs.com/easonliu/p/4784886.html

更清楚的说明

https://leetcode.com/discuss/71756/explanation-of-dp-o-n-time-complexity-o-1-space-complexity

https://leetcode.com/problems/find-the-celebrity/

http://www.cnblogs.com/easonliu/p/4785253.html

https://leetcode.com/problems/wiggle-sort/

http://blog.csdn.net/xudli/article/details/48749155

https://leetcode.com/problems/zigzag-iterator/

http://blog.csdn.net/xudli/article/details/48749219

https://leetcode.com/problems/inorder-successor-in-bst/

http://www.jianshu.com/p/218f686d6494

https://leetcode.com/problems/walls-and-gates/

https://segmentfault.com/a/1190000003906674

https://leetcode.com/problems/unique-word-abbreviation/

http://blog.csdn.net/xudli/article/details/48860911

https://leetcode.com/problems/word-pattern-ii/

http://www.cnblogs.com/jcliBlogger/p/4870514.html

https://leetcode.com/problems/flip-game/

http://www.aichengxu.com/view/77156

https://leetcode.com/problems/flip-game-ii/

下面有题目,但是解法有bug(递归之后没有恢复)

http://www.cnblogs.com/yrbbest/p/5043682.html

正确的解法在这里:

https://leetcode.com/discuss/64344/theory-matters-from-backtracking-128ms-to-dp-0ms

https://leetcode.com/problems/best-meeting-point/

http://blog.csdn.net/pointbreak1/article/details/49422265

https://leetcode.com/problems/binary-tree-longest-consecutive-sequence/

还行

http://blog.csdn.net/xudli/article/details/49493401

https://leetcode.com/problems/smallest-rectangle-enclosing-black-pixels/

以下O(mn)

http://blog.csdn.net/xudli/article/details/49738267

以下O(m log n + n log m)

https://leetcode.com/discuss/68246/c-java-python-binary-search-solution-with-explanation

http://www.cnblogs.com/jcliBlogger/p/4948140.html (一样的原理)

https://leetcode.com/problems/number-of-islands-ii/

下面介绍了QuickFind, QuickUnion的区别

http://www.cnblogs.com/EdwardLiu/p/5087633.html

下面有路径压缩:

https://leetcode.com/discuss/69572/easiest-java-solution-with-explanations

https://leetcode.com/problems/range-sum-query-2d-mutable/

不错

https://segmentfault.com/a/1190000004238792

https://leetcode.com/problems/sparse-matrix-multiplication/

http://blog.csdn.net/xiaohei00000/article/details/50429791

是基于以下讨论

https://leetcode.com/discuss/71968/regular-28-ms-math-solution-6-8-lines

https://leetcode.com/problems/binary-tree-vertical-order-traversal/

http://blog.csdn.net/qq508618087/article/details/50760661

https://leetcode.com/problems/shortest-distance-from-all-buildings/

http://www.cnblogs.com/grandyang/p/5297683.html

其实是借鉴了以下,但是我还是不明白怎么保证所有都联通

https://leetcode.com/discuss/74453/36-ms-c-solution

下面的倒是验证了所有都联通

https://segmentfault.com/a/1190000004187914

https://leetcode.com/problems/generalized-abbreviation/

解法很多很全

http://www.cnblogs.com/grandyang/p/5261569.html

https://leetcode.com/problems/number-of-connected-components-in-an-undirected-graph/

解法很清爽,并查集

https://segmentfault.com/a/1190000004224298

https://leetcode.com/problems/maximum-size-subarray-sum-equals-k/

http://blog.csdn.net/jmspan/article/details/51247447

https://leetcode.com/problems/largest-bst-subtree/

http://www.cnblogs.com/grandyang/p/5188938.html

https://leetcode.com/problems/nested-list-weight-sum/

http://www.cnblogs.com/grandyang/p/5340305.html

https://leetcode.com/problems/longest-substring-with-at-most-k-distinct-characters/

http://www.cnblogs.com/grandyang/p/5351347.html

https://leetcode.com/problems/moving-average-from-data-stream/

http://www.cnblogs.com/grandyang/p/5450001.html

https://leetcode.com/problems/design-tic-tac-toe/

解法2好

http://www.cnblogs.com/grandyang/p/5467118.html

https://leetcode.com/problems/android-unlock-patterns/

http://www.cnblogs.com/grandyang/p/5541012.html

https://leetcode.com/problems/design-snake-game/

http://www.cnblogs.com/grandyang/p/5558033.html

https://leetcode.com/problems/line-reflection/

http://blog.csdn.net/qq508618087/article/details/51756981

https://leetcode.com/problems/rearrange-string-k-distance-apart/

http://blog.csdn.net/qq508618087/article/details/51762258

https://leetcode.com/problems/logger-rate-limiter/

http://blog.csdn.net/jmspan/article/details/51697104

https://leetcode.com/problems/sort-transformed-array/

http://blog.csdn.net/qq508618087/article/details/51700774

https://leetcode.com/problems/bomb-enemy/

http://blog.csdn.net/qq508618087/article/details/51705806

http://blog.csdn.net/jmspan/article/details/51708425

https://leetcode.com/problems/design-hit-counter/

http://blog.csdn.net/jmspan/article/details/51738164

https://leetcode.com/problems/nested-list-weight-sum-ii/

http://blog.csdn.net/jmspan/article/details/51747784

https://leetcode.com/problems/find-leaves-of-binary-tree/

http://blog.csdn.net/jmspan/article/details/51760985

https://leetcode.com/problems/plus-one-linked-list/

http://blog.csdn.net/qq508618087/article/details/51779701

https://leetcode.com/problems/range-addition/

http://blog.csdn.net/jmspan/article/details/51787011 (第二种的好方法我也想到了哈哈)

https://leetcode.com/problems/design-phone-directory/

http://www.cnblogs.com/grandyang/p/5735205.html

https://leetcode.com/problems/valid-word-abbreviation

http://www.cnblogs.com/grandyang/p/5930369.html

本身题目比较简单,但是文章最后提到的前面那道 Generalized Abbreviation的解法却非常有意思:

http://www.cnblogs.com/grandyang/p/5261569.html

另外看到一个好的解法:

即把"i12iz4n"这样的缩写转换成"i.{12}iz.{4}n"

1     public boolean validWordAbbreviation(String word, String abbr) {
2         return word.matches(abbr.replaceAll("[1-9]\\d*", ".{$0}"));
3     }

https://leetcode.com/problems/minimum-unique-word-abbreviation

http://www.cnblogs.com/grandyang/p/5935836.html

解法一般,用缩写去轮询比较。

http://www.cnblogs.com/easonliu/p/4852129.html

这里的方法稍好一些,通过Hashmap来存储abbreviation.

https://leetcode.com/problems/sentence-screen-fitting

http://blog.csdn.net/mcf171/article/details/52770093

http://www.cnblogs.com/reboot329/p/5947854.html

时间: 2025-01-08 23:26:39

【Todo】所有Locked的题目的分析解答的相关文章

大公司面试经典数据结构与算法题C#解答

几个大公司(IBM.MicroSoft and so on)面试经典数据结构与算法题C#解答 1.链表反转 我想到了两种比较简单的方法 第一种是需要开一个新的链表,将原链表的元素从后到前的插入到新链表中(也就是原链表第一个元素被插入成新链表的最后一个元素). 第二种是不需要开新的链表,而是逐步反转原链表中元素的指向,例如: 原链表是 1->2->3->4->null  被  逐步修改为 ①2->1->null.3->4->null ②3->2->

2014马哥Linux0217中对0214三题的解答

前几天在做2014马哥Linux0214的作业的时候,发现其实这三题在0217中有解答,当然觉得马哥比自己写得好太多,所以忍不住要把马哥的答案贴出来,以供自己学习. 第一题:写一个脚本,用for循环实现显示/etc/init.d/functions./etc/rc.d/rc.sysinit./etc/fstab有多少行 #!/bin/bash for fileName in /etc/init.d/functions /etc/rc.d/rc.sysinit /etc/fstab;do line

上一题的解答(转载)

import java.util.InputMismatchException;import java.util.Scanner; public class hi{ public static void main(String[] args) { // TODO Auto-generated method stub input(3); } public static int[] input(int length) { Scanner scanner = new Scanner(System.in

JavaScript基础知识----六道有趣的Js基础题以及解答

题目: 1.找出数字数组中最大的元素(使用Math.max函数)2.转化一个数字数组为function数组(每个function都弹出相应的数字)3.给object数组进行排序(排序条件是每个元素对象的属性个数)4.利用JavaScript打印出Fibonacci数(不使用全局变量)5.实现如下语法的功能:var a = (5).plus(3).minus(6); //26.实现如下语法的功能:var a = add(2)(3)(4); //9 解答:1. var a = [10,1,2,3,4

数学建模2012A题部分解答基于R语言

1 library(xlsx) 2 library(nortest) 3 library(Kendall) 4 library(stats) 5 6 chart1 <- read.xlsx("E:/迅雷下载/cumcm2012problems/A/附件1-葡萄酒品尝评分表.xls",stringsAsFactors = FALSE,sheetIndex = 1,header = F,encoding = "UTF-8") 7 chart2 <- read

2013年南京大学研究生考试数学分析最后一题的解答

设$f$是$\mathbb R$上的周期为$1$的且$C^1$的函数.如果$f$满足条件$$f(x)+f\left(x+\frac{1}{2}\right)=f(2x),x\in\mathbb R$$ 证明$f(x)\equiv0$. 证明    设$$f(x)=\frac{a_{0}}{2}+\sum_{n=1}^{\infty}(a_{n}\cos 2n\pi x+b_{n}\sin 2n\pi x)$$ (因为$f$可导,所以上面的式子确实取等号)这样可以得到\begin{align*}f

组合题目的分析

首先不妨考虑1个特殊情况,当n趋于无穷的时候,|t| = 1, 显然可以. 然后考虑任意一个长度为2*n的区间.不妨设为[a, a + 2n] , 考虑该区间的任意 一个整数m, 显然m = (a + n) + r, 其中r属于[-n, n].故包含在该区间的ai都可以 写成ai = t + s, 其中t  = (a + n). 现在考虑对a1 , a2, ..., am分段 [a1, a1 + 2n], [a(m),  a(m) + 2n], [a(t), a(t) + 2n] 一共t个区间.

几个面试经典算法题Java解答

题目一: public class testClockwiseOutput { //顺时针打印一个矩阵 @Test public void test(){ int[][] num = new int[100][100]; int n = 4; int count =1; for(int i=0;i<n;i++){ for(int j =0;j<n;j++){ num[i][j]=count++; } } output(num,0,n-1); } public void output(int[]

07 斐波那契数列 08 跳台阶 两个题的解答相似

官方正规的数学界的斐波那契数列的定义: 波那契数列(Fibonacci sequence),又称黄金分割数列.因数学家列昂纳多·斐波那契(Leonardoda Fibonacci)以兔子繁殖为例子而引入,故又称为“兔子数列”,指的是这样一个数列:1.1.2.3.5.8.13.21.34.……在数学上,斐波纳契数列以如下被以递推的方法定义:F(1)=1,F(2)=1, F(n)=F(n-1)+F(n-2)(n>=3,n∈N*)在现代物理.准晶体结构.化学等领域,斐波纳契数列都有直接的应用. 是以1