随笔分类 -  Leetcode

摘要:Given a binary tree, return thepostordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[3,2,1].No... 阅读全文
posted @ 2014-10-22 13:43 Phoebe815 阅读(171) 评论(0) 推荐(0)
摘要:Given a binary tree, return thepreordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,2,3].Not... 阅读全文
posted @ 2014-10-22 13:36 Phoebe815 阅读(154) 评论(0) 推荐(0)
摘要:Given a binary tree, return theinordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,3,2].Note... 阅读全文
posted @ 2014-10-22 12:36 Phoebe815 阅读(162) 评论(0) 推荐(0)
摘要:Given two wordsword1andword2, find the minimum number of steps required to convertword1toword2. (each operation is counted as 1 step.)You have the fol... 阅读全文
posted @ 2014-10-21 05:26 Phoebe815 阅读(145) 评论(0) 推荐(0)
摘要:Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. 1 /** 2 * Definition for singly-linked ... 阅读全文
posted @ 2014-10-21 02:44 Phoebe815 阅读(163) 评论(0) 推荐(0)
摘要:Given a linked list, remove thenthnode from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After re... 阅读全文
posted @ 2014-10-21 02:06 Phoebe815 阅读(153) 评论(0) 推荐(0)
摘要:Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.Solution:... 阅读全文
posted @ 2014-10-21 01:43 Phoebe815 阅读(134) 评论(0) 推荐(0)
摘要:Given a sorted linked list, delete all duplicates such that each element appear onlyonce.For example,Given1->1->2, return1->2.Given1->1->2->3->3, retu... 阅读全文
posted @ 2014-10-21 01:32 Phoebe815 阅读(117) 评论(0) 推荐(0)
摘要:Given 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 algor... 阅读全文
posted @ 2014-10-21 01:13 Phoebe815 阅读(105) 评论(0) 推荐(0)
摘要:Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.Solution:此题是要求把罗马数字转换成数字。首先,学习一下罗马数字,参考罗马数字罗... 阅读全文
posted @ 2014-10-19 12:34 Phoebe815 阅读(158) 评论(0) 推荐(0)
摘要:Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in or... 阅读全文
posted @ 2014-10-19 06:22 Phoebe815 阅读(121) 评论(0) 推荐(0)
摘要:Implementatoito convert a string to an integer.Hint:Carefully consider all possible input cases. If you want a challenge, please do not see below and ... 阅读全文
posted @ 2014-10-19 06:16 Phoebe815 阅读(138) 评论(0) 推荐(0)
摘要:The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1is read off as"one 1"or11.11is read off as"tw... 阅读全文
posted @ 2014-10-19 05:45 Phoebe815 阅读(172) 评论(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: Pana... 阅读全文
posted @ 2014-10-19 03:46 Phoebe815 阅读(121) 评论(0) 推荐(0)
摘要:Implement strStr().Returns a pointer to the first occurrence of needle in haystack, ornullif needle is not part of haystack.Solution: 1 public class S... 阅读全文
posted @ 2014-10-18 07:32 Phoebe815 阅读(126) 评论(0) 推荐(0)
摘要:Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.Solution:N-Queens 问题的简化版。pu... 阅读全文
posted @ 2014-10-18 07:22 Phoebe815 阅读(121) 评论(0) 推荐(0)
摘要:Then-queens puzzle is the problem of placingnqueens on ann×nchessboard such that no two queens attack each other.Given an integern, return all distinc... 阅读全文
posted @ 2014-10-18 07:10 Phoebe815 阅读(165) 评论(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... 阅读全文
posted @ 2014-10-17 15:19 Phoebe815 阅读(130) 评论(0) 推荐(0)
摘要:Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull.Follow up:Can you solve it without using extra space?Sol... 阅读全文
posted @ 2014-10-17 15:01 Phoebe815 阅读(113) 评论(0) 推荐(0)
摘要:Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?Solution:快慢指针。 1 /** 2 * Definition for s... 阅读全文
posted @ 2014-10-17 14:20 Phoebe815 阅读(100) 评论(0) 推荐(0)