- 博客(20)
- 资源 (1)
- 收藏
- 关注
原创 110. Balanced Binary Tree
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 of every node never diffe
2017-07-06 22:13:15 191
原创 113. Path Sum II
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree and sum = 22, 5 /
2017-07-06 21:46:42 176
原创 21. Merge Two Sorted Lists
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.题解:合并两个有序的链表,解法有两种,一种是内部循环,一种是递归,递归的效率肯定不如函数内部循环,所以我的解法就是
2017-07-06 20:58:49 162
原创 104. Maximum Depth of Binary Tree 111. Minimum Depth of Binary Tree
104. Maximum Depth of Binary TreeGiven 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
2017-07-06 20:27:20 188
原创 100. Same Tree 101. Symmetric Tree
100. Same TreeGiven two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same
2017-07-06 19:33:28 152
原创 98. Validate Binary Search Tree
Given a binary tree, determine if it is a valid binary search tree (BST).题解:题意是判断一个二叉查找树是否合法,那么我们必须保证,右子树的所有的节点小于根节点,左字树的所有节点大于根节点;这道题的最大难点是为了满足以上的条件,必须满足一个左节点不仅要小于根节点,若根节点是上层的根节点左节点,那么根据d<b, b<a的递推
2017-07-06 17:05:06 125
原创 108. Convert Sorted Array to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.解题思路:升序数组构建而查找树,通过109的讲解(详情可见),我们发现最优解是中序遍历构建是最优解,而与升序链表不同的地方在于它的size是直接获取的;class Solution {privat
2017-07-06 15:05:21 115
原创 109. Convert Sorted List to Binary Search Tree
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.解题思路:其实这是个很经典的有序链表构建二叉查找树的问题,也就是先序遍历,后序遍历,中序遍历构建的问题,三者的代码如下:1. 先序遍历:class Solution {
2017-07-06 13:23:09 118
原创 11. Container With Most Water
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0
2017-07-02 02:35:47 117
原创 9. Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.解题思路:很经典的一个小算法题,判断一个int是不是一个回文数,相信方法有很多种,分解int,读位存储,判断首位是否相等,这是最普遍也是最傻瓜式的解法,如何做到简洁明了,其实很简单,时间复杂度为O(1),首先判断是不是负数,和非零的尾数为零的int
2017-07-02 02:13:09 122
原创 15. 3Sum
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note: The solution set must not contain
2017-07-01 13:24:31 147
原创 8. String to Integer (atoi)
Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input ca
2017-06-13 20:00:50 512
原创 7. Reverse Integer
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321click to show spoilers.Note:The input is assumed to be a 32-bit signed integer. Your function s
2017-06-13 17:04:22 146
原创 6. ZigZag Conversion
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H NA P L S I
2017-06-12 14:19:58 193
原创 5. Longest Palindromic Substring
Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.Example:Input: "babad"Output: "bab"Note: "aba" is also a valid answer.
2017-03-22 09:36:34 193
原创 3. Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the length is 3.Given "bbbbb", the answer is "
2017-03-07 20:25:49 165
原创 4. Median of Two Sorted Arrays
There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).题解:对于这道题自己的做法,自己
2017-03-04 18:25:10 137
原创 2. Add Two Numbers
You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return i
2017-03-04 13:19:12 156
原创 1. Two Sum
1. Two SumGiven an array ofintegers, return indices of the two numbers such that they add up to a specifictarget.You may assumethat each input would have exactly one solution, and you may not
2017-02-24 15:13:14 216
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人