![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
godleft90
这个作者很懒,什么都没留下…
展开
-
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原创 2014-12-19 14:54:05 · 300 阅读 · 0 评论 -
Binary Tree Preorder Traversal
问题描述:Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,2,3].Note: Recur原创 2014-12-10 10:53:06 · 290 阅读 · 0 评论 -
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 / \原创 2014-12-10 16:29:01 · 312 阅读 · 0 评论 -
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,原创 2014-12-10 18:42:03 · 727 阅读 · 0 评论 -
Two Sum
问题描述:Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the原创 2015-01-15 16:28:04 · 317 阅读 · 0 评论 -
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 hav原创 2015-01-16 16:25:08 · 250 阅读 · 0 评论 -
4Sum
问题描述:解决思路:算法1:O(n^3)我们可以仿照3sum的解决方法。这里枚举第一个和第二个数,然后对余下数的求2sum,算法复杂度为O(n^3)class Solution {public: vector > fourSum(vector &num, int target) { int n = num.size();原创 2015-01-16 16:51:39 · 302 阅读 · 0 评论 -
Remove Duplicates from Sorted List
问题描述:Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3.解决思路:定义两个指针b原创 2014-12-11 17:03:23 · 285 阅读 · 0 评论 -
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 tri原创 2015-01-15 18:02:04 · 292 阅读 · 0 评论 -
有效的括号序列
描述:给定一个字符串所表示的括号序列,包含以下字符: '(', ')', '{', '}', '[' and ']', 判定是否是有效的括号序列。样例括号必须依照 "()" 顺序表示, "()[]{}" 是有效的括号,但 "([)]"则是无效的括号。解题思路:使用栈class Solution {public: /** * @para原创 2017-03-23 08:52:02 · 399 阅读 · 0 评论 -
岛屿的个数
描述:给一个01矩阵,求不同的岛屿的个数。0代表海,1代表岛,如果两个1相邻,那么这两个1属于同一个岛。我们只考虑上下左右为相邻。样例在矩阵:[ [1, 1, 0, 0, 0], [0, 1, 0, 0, 1], [0, 0, 0, 1, 1], [0, 0, 0, 0, 0], [0, 0, 0, 0, 1]]中有 3 个岛.原创 2017-03-23 09:00:46 · 1143 阅读 · 0 评论 -
Excel Sheet Column Number
问题描述:Related to question Excel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example: A -> 1 B -> 2 C -> 3原创 2015-01-14 16:31:15 · 372 阅读 · 0 评论 -
Linked List Cycle
问题描述:Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?解决思路:采用快慢指针的方法,快指针一次走两步,慢指针一次走一步,如果链表中有环的话,经过走一定的步数之后快慢指针一定会相遇的,当然如果没有环就需原创 2014-12-08 16:18:39 · 271 阅读 · 0 评论 -
Unique Binary Search Trees
问题描述:Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's. 1 3 3 2原创 2014-12-08 15:57:36 · 239 阅读 · 0 评论 -
Maximum Depth of Binary Tree
问题描述: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 leaf node.解决思路:DFS分别求出左子树和右子树的最大深度然原创 2014-12-04 16:20:03 · 247 阅读 · 0 评论 -
Same Tree
问题描述:Given 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 value.原创 2014-12-04 16:47:58 · 289 阅读 · 0 评论 -
Single Number
问题描述:Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it withou原创 2014-12-04 15:49:41 · 271 阅读 · 0 评论 -
Intersection of Two Linked Lists
问题描述:For example, the following two linked lists:A: a1 → a2 ↘ c1 → c2 → c3 ↗ B: b1 → b2 → b3begin to in原创 2014-12-22 15:09:51 · 258 阅读 · 0 评论 -
Majority Element
问题描述:Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majori原创 2014-12-22 14:12:20 · 374 阅读 · 0 评论 -
ZigZag Conversion
class Solution {public: string convert(string s, int nRows) { if(s.empty() || nRows <= 1 || s.length() < nRows) return s; string sub[nRows]; int pos[nRows];原创 2014-12-11 21:28:22 · 273 阅读 · 0 评论 -
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 (i原创 2014-12-08 14:50:12 · 283 阅读 · 0 评论 -
Palindrome Number
问题描述:Determine whether an integer is a palindrome. Do this without extra space.click to show spoilers.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking o原创 2014-12-23 15:26:53 · 244 阅读 · 0 评论 -
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: Recurs原创 2014-12-09 17:19:40 · 343 阅读 · 0 评论 -
最后一个单词的长度
描述:给定一个字符串, 包含大小写字母、空格' ',请返回其最后一个单词的长度。如果不存在最后一个单词,请返回 0 。样例:给定 s = "Hello World",返回 5。代码:class Solution {public: /** * @param s A string * @return the length of last原创 2017-03-23 09:06:28 · 380 阅读 · 0 评论