摘要:
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?public class Solution { public int singleNumber(int[] A) { int ones = 0; in... 阅读全文
posted @ 2014-01-06 11:42
23lalala
阅读(129)
评论(0)
推荐(0)
摘要:
A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list./** * Definition for singly-linked list with a random pointer. * class RandomListNode { * int label; * RandomListNode next, random... 阅读全文
posted @ 2014-01-06 11:42
23lalala
阅读(131)
评论(0)
推荐(0)
摘要:
Given a stringsand a dictionary of wordsdict, determine ifscan be segmented into a space-separated sequence of one or more dictionary words.For example, givens="leetcode",dict=["leet", "code"].Return true because"leetcode"can be segmented as"leet code&quo 阅读全文
posted @ 2014-01-06 11:42
23lalala
阅读(132)
评论(0)
推荐(0)
摘要:
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama"is a palindrome."race a car"isnota palindrome.Note:Have you consider that the string might be empty? This is a good question to 阅读全文
posted @ 2014-01-06 11:42
23lalala
阅读(151)
评论(0)
推荐(0)
摘要:
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 still work?Note:You may only use constant extra space.For example,Given the following binary tree, 1 / \ 2 3 / \ \ 4 5 ... 阅读全文
posted @ 2014-01-06 11:41
23lalala
阅读(176)
评论(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 static HashMap dp = new HashMap(); public int climbStairs(int n) { if (dp.containsKey(n)){ ... 阅读全文
posted @ 2014-01-06 11:40
23lalala
阅读(143)
评论(0)
推荐(0)
摘要:
Given an array where elements are sorted in ascending order, convert it to a height balanced BST./** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution { public static Tree... 阅读全文
posted @ 2014-01-06 11:40
23lalala
阅读(109)
评论(0)
推荐(0)
摘要:
Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees ofeverynode never differ by more than 1./** * Definition for binary tree * public class TreeNode { * int val; * TreeNode ... 阅读全文
posted @ 2014-01-06 11:40
23lalala
阅读(153)
评论(0)
推荐(0)
摘要:
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 / \ 2 2 / \ / \3 4 4 3But the following is not: 1 / \ 2 2 \ \ 3 3Note:Bonus points if you could solve it both recursively and iterati... 阅读全文
posted @ 2014-01-06 11:40
23lalala
阅读(150)
评论(0)
推荐(0)
摘要:
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-06 11:40
23lalala
阅读(119)
评论(0)
推荐(0)

浙公网安备 33010602011771号