LeetCode
文章平均质量分 73
wantiangen1992
这个作者很懒,什么都没留下…
展开
-
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 · 147 阅读 · 0 评论 -
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 · 180 阅读 · 0 评论 -
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 · 168 阅读 · 0 评论 -
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 · 152 阅读 · 0 评论 -
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 · 176 阅读 · 0 评论 -
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 · 139 阅读 · 0 评论 -
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 · 105 阅读 · 0 评论 -
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 · 110 阅读 · 0 评论 -
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 · 495 阅读 · 0 评论 -
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 · 138 阅读 · 0 评论 -
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 · 183 阅读 · 0 评论 -
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 · 109 阅读 · 0 评论 -
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 · 205 阅读 · 0 评论 -
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 · 110 阅读 · 0 评论 -
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 · 138 阅读 · 0 评论 -
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 · 184 阅读 · 0 评论 -
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 · 127 阅读 · 0 评论 -
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 · 157 阅读 · 0 评论 -
8.22证明
原创 2017-07-06 23:29:09 · 131 阅读 · 0 评论