![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
文章平均质量分 57
xshalk
这个作者很懒,什么都没留下…
展开
-
[LeetCode]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 everynode never differ原创 2012-11-05 17:55:51 · 1102 阅读 · 2 评论 -
[LeetCode]Distinct Subsequences
Given a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string by deleting some (can be n原创 2012-11-25 23:05:18 · 1971 阅读 · 0 评论 -
[LeetCode]Divide Two Integers
Divide two integers without using multiplication, division and mod operator.思路:先想到的是做减法,但是效率在两数差距大的时候复杂度很高, 之后想到移位的方式,把除数和余数提高,复杂度较低。 例如 19 除以 3 , 记录两个值 除数 3 商1 , 移原创 2012-11-26 17:00:56 · 1711 阅读 · 0 评论 -
[LeeCode]Edit Distance
Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a w原创 2012-11-26 17:41:20 · 1498 阅读 · 0 评论 -
[LeetCode]Convert Sorted Array to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.平分,递归。/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left;原创 2012-11-14 16:32:09 · 577 阅读 · 0 评论 -
[LeetCode]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). F原创 2012-11-14 16:12:52 · 1384 阅读 · 0 评论 -
[LeetCode]Count and Say
The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or 11.11 is read off as "two 1s" or 21.21 is read原创 2012-11-14 17:00:27 · 7344 阅读 · 0 评论 -
[LeetCode]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.由于链表不能随机访问,只能修改链表结构,要不就只能遍历求长度,再求出中间位置。这里不能修改结构,总是要不断的遍历,求中间位置,十分罗嗦。简单如前一题,遍历一遍,把值原创 2012-11-14 16:40:35 · 969 阅读 · 0 评论 -
[LeetCode]Construct Binary Tree from Preorder and Inorder Traversal
Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.和前一题类似/** * Definition for binary tree * struct T原创 2012-11-14 15:13:57 · 898 阅读 · 0 评论 -
[LeetCode]Decode Ways
A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the total nu原创 2012-11-15 11:41:28 · 2698 阅读 · 2 评论 -
[LeetCode]Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?求斐波那契, f(n) = f(n-1)+f(n-2)原创 2012-11-06 17:12:55 · 513 阅读 · 0 评论 -
[Leetcode_PY]Longest Substring Without Repeating Characters
题目 Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for “abcabcbb” is “abc”, which the length is 3.原创 2016-01-20 15:54:58 · 448 阅读 · 0 评论 -
[LeetCode]Combination Sum
Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen from C unlimited原创 2012-11-08 16:33:27 · 1665 阅读 · 0 评论 -
[LeetCode]Construct Binary Tree from Inorder and Postorder Traversal
Construct Binary Tree from Inorder and Postorder TraversalGiven inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the原创 2012-11-08 18:52:18 · 2811 阅读 · 0 评论 -
[LeetCode]Binary Tree Zigzag Level Order Traversal
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).For example:Given binar原创 2012-11-06 16:08:31 · 1059 阅读 · 0 评论 -
[Leetcode]Anagram
Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.先查了一下单词,意思是单词重排, abc 和 bca 是anagramshttp://en.wikipedia.org/wiki/Anagram原创 2012-11-05 17:05:23 · 2765 阅读 · 1 评论 -
[Leetcode]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:Elements in a triplet原创 2012-11-05 13:03:31 · 10970 阅读 · 4 评论 -
[Leetcode]3Sum Closest
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exa原创 2012-11-05 13:37:07 · 1267 阅读 · 0 评论 -
[Leetcode] Add Binary
Add BinaryGiven two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".思路: 对齐, 计算当前位和进位; 如果位较长,让我想到了先行进位加法器,不过这里的计算不能并行,也原创 2012-11-05 13:59:06 · 5563 阅读 · 0 评论 -
[LeetCode] SUM4
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note:原创 2012-11-05 20:41:38 · 663 阅读 · 0 评论 -
[LeetCode]Best Time to Buy and Sell Stock
题为:股票最佳买卖时机Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy one and sell one s原创 2012-11-05 23:54:58 · 3149 阅读 · 2 评论 -
[LeetCode]Add Two Numbers
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a link原创 2012-11-05 15:00:33 · 1686 阅读 · 0 评论 -
[LeetCode]Best Time to Buy and Sell Stock II
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy原创 2012-11-06 11:07:15 · 1053 阅读 · 0 评论 -
[LeetCode]Binary Tree Inorder Traversal
Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,3,2].Note: Recursive solutio原创 2012-11-06 12:00:52 · 1941 阅读 · 0 评论 -
[LeetCode]Binary Tree Level Order Traversal
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree {3,9,20,#,#,15,7}, 3 / \ 9 20原创 2012-11-06 15:30:15 · 725 阅读 · 0 评论 -
[LeetCode]Binary Tree Level Order Traversal II
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree {3,9,20,#,#,15,7}原创 2012-11-06 15:58:08 · 3328 阅读 · 1 评论 -
[LeetCode_PY] 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)).思路:方法一: 先做最笨的方法,两个列表原创 2016-03-14 17:21:35 · 379 阅读 · 0 评论