摘要: Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ ... 阅读全文
posted @ 2014-01-24 17:01 Razer.Lu 阅读(153) 评论(0) 推荐(0) 编辑
摘要: You are climbing a stair case. It takesnsteps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?public class Solution { public int climbStairs(int n) { int[] level = new int[n+1]; level[0] = 0; level[1] = 1; ... 阅读全文
posted @ 2014-01-24 16:56 Razer.Lu 阅读(115) 评论(0) 推荐(0) 编辑
摘要: You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single ... 阅读全文
posted @ 2014-01-24 16:51 Razer.Lu 阅读(157) 评论(0) 推荐(0) 编辑
摘要: Search in Rotated Sorted ArraySuppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e.,0 1 2 4 5 6 7might become4 5 6 7 0 1 2).You are given a target value to search. If found in the array return its index, otherwise return -1.You may assume no duplicate exists in the array.A[ 阅读全文
posted @ 2014-01-24 16:24 Razer.Lu 阅读(164) 评论(0) 推荐(0) 编辑
摘要: 这里使用了额外的存储空间,可以使用双指针来实现,不需额外的存储空间./** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */public class Solution { public ListNode deleteDuplicates(ListNode head) { ... 阅读全文
posted @ 2014-01-24 15:26 Razer.Lu 阅读(166) 评论(0) 推荐(0) 编辑
摘要: Given a string containing just the characters'(',')','{','}','['and']', determine if the input string is valid.The brackets must close in the correct order,"()"and"()[]{}"are all valid but"(]"and"([)]"are not.pub 阅读全文
posted @ 2014-01-24 13:14 Razer.Lu 阅读(140) 评论(0) 推荐(0) 编辑
摘要: public class Solution { public void setZeroes(int[][] matrix) { if(matrix.length == 0) { return; } int r = matrix.length; int c = matrix[0].length; boolean rZeros = false; boolean cZeros = false; for(int i = 0 ; i < r ; i++){... 阅读全文
posted @ 2014-01-24 12:51 Razer.Lu 阅读(200) 评论(0) 推荐(0) 编辑
摘要: public class Solution { public double pow(double x, int n) { if(n<0){ return 1.0/powHelper(x,n); }else{ return powHelper(x, n); } } public double powHelper(double x, int n){ if(n == 0){ return 1; } double... 阅读全文
posted @ 2014-01-24 12:37 Razer.Lu 阅读(119) 评论(0) 推荐(0) 编辑
摘要: 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].遍历list,将每个interval插入到result中去insert interval : http://www.cnblogs.com/RazerLu/p/3532267.html/** * Definition for an interval. * public class Interval { * int st... 阅读全文
posted @ 2014-01-24 12:27 Razer.Lu 阅读(127) 评论(0) 推荐(0) 编辑
摘要: Given a set ofnon-overlappingintervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their start times.Example 1:Given intervals[1,3],[6,9], insert and merge[2,5]in as[1,5],[6,9].Example 2:Given[1,2],[3,5],[6,7],[8 阅读全文
posted @ 2014-01-24 12:22 Razer.Lu 阅读(154) 评论(0) 推荐(0) 编辑
摘要: Given an unsorted integer array, find the first missing positive integer.For example,Given[1,2,0]return3,and[3,4,-1,1]return2.Your algorithm should run inO(n)time and uses constant space.ref:http://www.cnblogs.com/AnnieKim/archive/2013/04/21/3034631.html虽然不能再另外开辟非常数级的额外空间,但是可以在输入数组上就地进行swap操作。思路:交换数 阅读全文
posted @ 2014-01-24 02:52 Razer.Lu 阅读(208) 评论(0) 推荐(0) 编辑