摘要: Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node./** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { v... 阅读全文
posted @ 2014-01-29 09:11 Razer.Lu 阅读(133) 评论(0) 推荐(0)
摘要: Swap Nodes in PairsGiven a linked list, swap every two adjacent nodes and return its head.For example,Given1->2->3->4, you should return the list as2->1->4->3.Your algorithm should use only constant space. You maynotmodify the values in the list, only nodes itself can be changed./* 阅读全文
posted @ 2014-01-29 09:08 Razer.Lu 阅读(283) 评论(0) 推荐(0)
摘要: Given a collection of numbers, return all possible permutations.For example,[1,2,3]have the following permutations:[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2], and[3,2,1].Analysis:The idea of this classic problem is to use backtracking.We want to get permutations, which is mainly about swap values in th 阅读全文
posted @ 2014-01-29 08:57 Razer.Lu 阅读(314) 评论(0) 推荐(0)
摘要: Permutation SequenceThe set[1,2,3,…,n]contains a total ofn! unique permutations.By listing and labeling all of the permutations in order,We get the following sequence (ie, forn= 3):"123""132""213""231""312""321"Givennandk, return thekthperm 阅读全文
posted @ 2014-01-29 07:48 Razer.Lu 阅读(409) 评论(1) 推荐(0)