摘要: Given an integern, generate a square matrix filled with elements from 1 ton2in spiral order.For example,Givenn=3,You should return the following matrix:[ [ 1, 2, 3 ], [ 8, 9, 4 ], [ 7, 6, 5 ]]生成的过程为 (1) 横向生成 1,2 (2) 纵向生成 3,4 (3) 横向生成 5,6 (4) 纵向生成 7,8 (5) 生成 9public class ... 阅读全文
posted @ 2014-02-20 16:10 Razer.Lu 阅读(173) 评论(0) 推荐(0) 编辑
摘要: Given a stringSand a stringT, count the number of distinct subsequences ofTinS.A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (ie,"ACE" 阅读全文
posted @ 2014-02-20 16:06 Razer.Lu 阅读(188) 评论(0) 推荐(0) 编辑
摘要: Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Ref:http://fisherlei.blogspot.com/20... 阅读全文
posted @ 2014-02-20 15:24 Razer.Lu 阅读(228) 评论(0) 推荐(0) 编辑
摘要: Given an array of integers, every element appearsthreetimes except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?Ref :http://fisherlei.blogspot.com/2013/11/leetcode-single-number-ii-solution.html[Thoughts] 阅读全文
posted @ 2014-02-20 14:45 Razer.Lu 阅读(196) 评论(0) 推荐(0) 编辑
摘要: Given an absolute path for a file (Unix-style), simplify it.For example,path="/home/", =>"/home"path="/a/./b/../../c/", =>"/c"click to show corner cases.Corner Cases:Did you consider the case wherepath="/../"?In this case, you should return&quo 阅读全文
posted @ 2014-02-20 13:57 Razer.Lu 阅读(247) 评论(0) 推荐(0) 编辑
摘要: Evaluate the value of an arithmetic expression inReverse Polish Notation.Valid operators are+,-,*,/. Each operand may be an integer or another express... 阅读全文
posted @ 2014-02-20 13:42 Razer.Lu 阅读(187) 评论(0) 推荐(0) 编辑
摘要: Givennpoints on a 2D plane, find the maximum number of points that lie on the same straight line.思路: 从 points[] 中依次取出一个点,然后依次和后面一个点组成一条直线。 y = ax+b;然后... 阅读全文
posted @ 2014-02-20 10:27 Razer.Lu 阅读(220) 评论(0) 推荐(0) 编辑
摘要: Sort a linked list inO(nlogn) time using constant space complexity.Merge sort先根据mid node把list 分割为 单个 node ,然后merge/** * Definition for singly-linked l... 阅读全文
posted @ 2014-02-20 10:19 Razer.Lu 阅读(264) 评论(0) 推荐(0) 编辑