随笔分类 -  LeetCode OJ

刷题
摘要:Given an array where elements are sorted in ascending order, convert it to a height balanced BST. Subscribe to see which companies asked this question 阅读全文
posted @ 2016-02-28 14:23 sdlwlxf 阅读(175) 评论(0) 推荐(0)
摘要:Given a binary tree, flatten it to a linked list in-place. For example,Given 1 / \ 2 5 / \ \ 3 4 6 The flattened tree should look like: 1 \ 2 \ 3 \ 4 阅读全文
posted @ 2016-02-28 13:04 sdlwlxf 阅读(177) 评论(0) 推荐(0)
摘要:Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only 阅读全文
posted @ 2016-02-27 21:22 sdlwlxf 阅读(137) 评论(0) 推荐(0)
摘要:Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum. F 阅读全文
posted @ 2016-02-27 20:40 sdlwlxf 阅读(155) 评论(0) 推荐(0)
摘要:Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume that duplicates do not exist in the tree. Subscribe to 阅读全文
posted @ 2016-01-31 18:03 sdlwlxf 阅读(147) 评论(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 l 阅读全文
posted @ 2016-01-31 16:04 sdlwlxf 阅读(167) 评论(0) 推荐(0)
摘要:Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According to the definition of LCA on Wikipedia: “The lowes 阅读全文
posted @ 2016-01-30 16:20 sdlwlxf 阅读(158) 评论(0) 推荐(0)
摘要:You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time 阅读全文
posted @ 2016-01-30 12:41 sdlwlxf 阅读(177) 评论(0) 推荐(0)
摘要:Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST. Calling next() will return the n 阅读全文
posted @ 2016-01-28 22:32 sdlwlxf 阅读(137) 评论(0) 推荐(0)
摘要:Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree: 1 / \ 2 3 \ 5 All root-to-leaf paths are: ["1->2->5" 阅读全文
posted @ 2016-01-27 21:11 sdlwlxf 阅读(133) 评论(0) 推荐(0)
摘要:Given a list of non negative integers, arrange them such that they form the largest number.For example, given[3, 30, 34, 5, 9], the largest formed num... 阅读全文
posted @ 2016-01-25 21:56 sdlwlxf 阅读(141) 评论(0) 推荐(0)
摘要:Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".For C programmers: Try to solv... 阅读全文
posted @ 2016-01-22 21:09 sdlwlxf 阅读(224) 评论(0) 推荐(0)
摘要:Given two integers representing the numerator and denominator of a fraction, return the fraction in string format.If the fractional part is repeating,... 阅读全文
posted @ 2016-01-22 20:05 sdlwlxf 阅读(167) 评论(0) 推荐(0)
摘要:Compare two version numbersversion1andversion2.Ifversion1>version2return 1, ifversion1 a2) return 1; else if (a1 < a2) re... 阅读全文
posted @ 2016-01-19 21:17 sdlwlxf 阅读(186) 评论(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... 阅读全文
posted @ 2016-01-19 20:16 sdlwlxf 阅读(119) 评论(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 / \ ... 阅读全文
posted @ 2016-01-18 21:12 sdlwlxf 阅读(192) 评论(0) 推荐(0)
摘要:Related to questionExcel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example: A ... 阅读全文
posted @ 2016-01-18 20:20 sdlwlxf 阅读(159) 评论(0) 推荐(0)
摘要:Given an integern, return the number of trailing zeroes inn!.Note:Your solution should be in logarithmic time complexity.Credits:Special thanks to@tsf... 阅读全文
posted @ 2016-01-18 19:20 sdlwlxf 阅读(136) 评论(0) 推荐(0)
摘要:Write an algorithm to determine if a number is "happy".A happy number is a number defined by the following process: Starting with any positive integer... 阅读全文
posted @ 2016-01-16 21:04 sdlwlxf 阅读(108) 评论(0) 推荐(0)
摘要:Description:Count the number of prime numbers less than a non-negative number,n.Credits:Special thanks to@mithmattfor adding this problem and creating... 阅读全文
posted @ 2016-01-16 20:30 sdlwlxf 阅读(126) 评论(0) 推荐(0)