摘要: Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary tree, 1 ... 阅读全文
posted @ 2014-02-26 09:22 Averill Zheng 阅读(142) 评论(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?Have you been asked this question in an interview?/**We can use the bit operation to do this 阅读全文
posted @ 2014-02-26 05:30 Averill Zheng 阅读(223) 评论(0) 推荐(0) 编辑
摘要: Given an array of integers, every element appearstwiceexcept for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?Have you been asked this question in an interview?public class Solution { public int singleNumb... 阅读全文
posted @ 2014-02-25 12:23 Averill Zheng 阅读(145) 评论(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.Have you been asked this question in an interview?YesDiscuss/** * Definition for singly-linked list with a random pointer. * class RandomL 阅读全文
posted @ 2014-02-25 07:56 Averill Zheng 阅读(148) 评论(0) 推荐(0) 编辑
摘要: Implement strStr().Returns a pointer to the first occurrence of needle in haystack, ornullif needle is not part of haystack.This is a simple problem,public class Solution { public String strStr(String haystack, String needle) { int hlen = haystack.length(), nlen = needle.length(); S... 阅读全文
posted @ 2014-02-24 13:27 Averill Zheng 阅读(118) 评论(0) 推荐(0) 编辑
摘要: Implement wildcard pattern matching with support for'?'and'*'.'?' Matches any single character.'*' Matches any sequence of characters (including the e... 阅读全文
posted @ 2014-02-24 12:04 Averill Zheng 阅读(168) 评论(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-02-23 01:10 Averill Zheng 阅读(146) 评论(0) 推荐(0) 编辑
摘要: Implement regular expression matching with support for'.'and'*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the entire input string (not partial).The function prototype should be:bool isMatch(const char 阅读全文
posted @ 2014-02-22 10:03 Averill Zheng 阅读(126) 评论(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:Recursive solution is trivial, could you do it iteratively?confused what"{1,#,2,3}"means?> read more on how binary tree is serialized on OJ./** * 阅读全文
posted @ 2014-02-17 18:55 Averill Zheng 阅读(139) 评论(0) 推荐(0) 编辑
摘要: 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-02-17 18:31 Averill Zheng 阅读(138) 评论(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].Note:Recursive solution is trivial, could you do it iteratively?/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode ... 阅读全文
posted @ 2014-02-17 18:10 Averill Zheng 阅读(139) 评论(0) 推荐(0) 编辑
摘要: Given a singly linked listL:L0→L1→…→Ln-1→Ln,reorder it to:L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For example,Given{1,2,3,4}, reorder it to{1,4,2,3}./** * Definition for singly-linked list. * class ListNode { * int val; * ListNode next; * ListN... 阅读全文
posted @ 2014-02-17 17:32 Averill Zheng 阅读(115) 评论(0) 推荐(0) 编辑
摘要: Sort a linked list using insertion sort./** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */public class Solution { public ListNode insertionSortList(ListNode head) {... 阅读全文
posted @ 2014-02-17 15:22 Averill Zheng 阅读(126) 评论(0) 推荐(0) 编辑
摘要: Sort a linked list inO(nlogn) time using constant space complexity.Method 1: This code can be accepted by leetcode online judge. The code is the implementation of the meger sort idea./** * Definition for singly-linked list. * class ListNode { * int val; * ListNode next; * ListNode(int x)... 阅读全文
posted @ 2014-02-17 11:41 Averill Zheng 阅读(179) 评论(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?/**... 阅读全文
posted @ 2014-02-12 06:31 Averill Zheng 阅读(145) 评论(0) 推荐(0) 编辑
摘要: Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?/** * Definition for singly-linked list. * class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */public class Sol... 阅读全文
posted @ 2014-02-12 06:27 Averill Zheng 阅读(150) 评论(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-02-12 06:05 Averill Zheng 阅读(133) 评论(0) 推荐(0) 编辑
摘要: Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example,S="ADOBECODEBA... 阅读全文
posted @ 2014-02-11 12:56 Averill Zheng 阅读(161) 评论(0) 推荐(0) 编辑
摘要: Given a strings, partitionssuch that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning ofs... 阅读全文
posted @ 2014-02-11 00:34 Averill Zheng 阅读(164) 评论(0) 推荐(0) 编辑
摘要: Given a strings, partitionssuch that every substring of the partition is a palindrome.Return all possible palindrome partitioning ofs.For example, givens="aab",Return [ ["aa","b"], ["a","a","b"] ]Discusspublic class Solution { public ArrayL 阅读全文
posted @ 2014-02-10 11:34 Averill Zheng 阅读(144) 评论(0) 推荐(0) 编辑