
LeetCode
文章平均质量分 73
Yangtong157
这个作者很懒,什么都没留下…
展开
-
235. Lowest Common Ancestor of a Binary Search Tree | 二叉查找树两个节点的最低共同祖先
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined betw原创 2017-05-03 21:15:54 · 410 阅读 · 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-02-26 15:12:53 · 465 阅读 · 0 评论 -
234. Palindrome Linked List | 判断一个单链表是否是回文
Given a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?Subscribe to see which companies asked this question.思路:获得链表的长度,逆置原创 2017-03-08 15:59:27 · 317 阅读 · 0 评论 -
434. Number of Segments in a String | 判断字符串中单词的数量
Count the number of segments in a string, where a segment is defined to be a contiguous sequence of non-space characters.Please note that the string does not contain any non-printable characters.原创 2017-02-25 21:24:02 · 469 阅读 · 0 评论 -
101. Symmetric Tree | 判断二叉树是否为镜像二叉树
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \ / \3 4 4 3原创 2017-02-24 16:05:27 · 307 阅读 · 0 评论 -
401. Binary Watch | 二进制手表
A binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom represent the minutes (0-59).Each LED represents a zero or one, with the least significant bit o原创 2017-02-16 11:10:13 · 352 阅读 · 0 评论 -
409. Longest Palindrome | 判断能组成的最长回文
Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters.This is case sensitive, for example "Aa" is not con原创 2017-02-15 20:28:48 · 275 阅读 · 0 评论 -
169. 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 majority element原创 2017-02-15 19:46:52 · 293 阅读 · 0 评论 -
100. 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.Subscr原创 2017-02-15 19:31:09 · 277 阅读 · 0 评论 -
171. Excel Sheet Column Number | 计算Excel列数
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 ...原创 2017-02-15 17:44:14 · 279 阅读 · 0 评论 -
107. 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,null,null,1原创 2017-02-24 11:17:07 · 259 阅读 · 0 评论 -
237. Delete Node in a Linked List | 删除单链表的节点
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value原创 2017-02-15 17:09:16 · 218 阅读 · 0 评论 -
345. Reverse Vowels of a String | 逆置字符串中的元音字母
Write a function that takes a string as input and reverse only the vowels of a string.Example 1:Given s = "hello", return "holle".Example 2:Given s = "leetcode", return "leotcede".Note原创 2017-02-23 16:53:16 · 667 阅读 · 0 评论 -
141. 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?Subscribe to see which companies asked this question.思路:用两个遍历指针,一个每次前进一步原创 2017-02-26 19:26:27 · 375 阅读 · 0 评论 -
Find Bottom Left Tree Value |找到二叉树最后一层的最左边的节点的值
Given a binary tree, find the leftmost value in the last row of the tree.Example 1:Input: 2 / \ 1 3Output:1Example 2: Input: 1 / \ 2 3原创 2017-03-11 15:05:45 · 2908 阅读 · 0 评论 -
222. Count Complete Tree Nodes | 完全二叉树的节点数
Given a complete binary tree, count the number of nodes.Definition of a complete binary tree from Wikipedia:In a complete binary tree every level, except possibly the last, is completely filled,原创 2017-04-16 20:29:06 · 454 阅读 · 0 评论 -
103. 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 binary原创 2017-05-02 15:13:02 · 400 阅读 · 0 评论 -
129. Sum Root to Leaf Numbers | 二叉树整数和
Total Accepted: 105665Total Submissions: 295189Difficulty: MediumContributor: LeetCodeGiven a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.A原创 2017-04-15 20:45:33 · 360 阅读 · 0 评论 -
199. Binary Tree Right Side View | 从右边看二叉树得到的集合
Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.For example:Given the following binary tree, 1原创 2017-04-19 16:25:26 · 419 阅读 · 0 评论 -
257. Binary Tree Paths | 二叉树的路径
Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths are:["1->2->5", "1->3"]Cre原创 2017-04-14 20:04:49 · 830 阅读 · 0 评论 -
230. Kth Smallest Element in a BST | 二叉排序树中查找第K小的数
Given a binary search tree, write a function kthSmallest to find the kth smallest element in it.Note: You may assume k is always valid, 1 ? k ? BST's total elements.Follow up:What if the原创 2017-04-18 21:48:34 · 751 阅读 · 1 评论 -
538. Convert BST to Greater Tree | 二叉排序树转换成Greater树
Given a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus sum of all keys greater than the original key in BST.Exam原创 2017-04-14 15:01:53 · 504 阅读 · 0 评论 -
543. Diameter of Binary Tree | 二叉树的“直径”
Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between any two nodes in a tree. This path may or may n原创 2017-04-14 14:31:10 · 1035 阅读 · 0 评论 -
508. Most Frequent Subtree Sum | 查找子树和中出现次数最多的和
Given the root of a tree, you are asked to find the most frequent subtree sum. The subtree sum of a node is defined as the sum of all the node values formed by the subtree rooted at that node (includi原创 2017-03-15 16:22:55 · 715 阅读 · 0 评论 -
477. Total Hamming Distance | 整数间数的二进制中不同的位数
The Hamming distance between two integers is the number of positions at which the corresponding bits are different.Now your job is to find the total Hamming distance between all pairs of the giv原创 2017-03-24 16:26:04 · 337 阅读 · 0 评论 -
445. Add Two Numbers II | 链表的整数相加
Total Accepted: 15900Total Submissions: 34368Difficulty: MediumContributors: AdminYou are given two non-empty linked lists representing two non-negative integers. The most significant digit co原创 2017-03-24 15:40:27 · 370 阅读 · 0 评论 -
318. Maximum Product of Word Lengths | 字符串长度相乘最大值
Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where the two words do not share common letters. You may assume that each word will contain only lower case le原创 2017-04-08 20:27:46 · 437 阅读 · 0 评论 -
367. Valid Perfect Square |计算一个数是否是一个数的平方
Given a positive integer num, write a function which returns True if num is a perfect square else False.Note: Do not use any built-in library function such as sqrt.Example 1:Input: 16Return原创 2017-02-23 16:33:09 · 464 阅读 · 0 评论 -
235. Lowest Common Ancestor of a Binary Search Tree | 二叉搜索树任意两点的最低共同父节点
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined betw原创 2017-02-23 15:38:58 · 316 阅读 · 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./** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode原创 2017-02-23 10:56:36 · 307 阅读 · 0 评论 -
258. Add Digits | 一个数各位数相加
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has on原创 2017-02-12 16:57:09 · 484 阅读 · 0 评论 -
506. Relative Ranks | 分数排名
Given scores of N athletes, find their relative ranks and the people with the top three highest scores, who will be awarded medals: "Gold Medal", "Silver Medal" and "Bronze Medal".Example 1:In原创 2017-02-12 16:09:54 · 364 阅读 · 0 评论 -
35. Search Insert Position | 找数
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.原创 2017-02-20 19:40:52 · 281 阅读 · 0 评论 -
501. Find Mode in Binary Search Tree | 二叉搜索树重复的节点
Given a binary search tree (BST) with duplicates, find all the mode(s) (the most frequently occurred element) in the given BST.Assume a BST is defined as follows:The left subtree of a node c原创 2017-02-20 15:47:41 · 834 阅读 · 0 评论 -
231. Power of Two | 判断2的幂
Given an integer, write a function to determine if it is a power of two.Credits:Special thanks to @jianchao.li.fighter for adding this problem and creating all test cases.Subscribe to se原创 2017-02-19 21:14:17 · 290 阅读 · 0 评论 -
202. Happy Number | 开心数
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, replace the number by the sum of the squares原创 2017-02-19 20:42:09 · 452 阅读 · 0 评论 -
121. 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 share of the stock),原创 2017-02-19 20:03:52 · 305 阅读 · 0 评论 -
405. Convert a Number to Hexadecimal | 10进制整数转16进制数
Given an integer, write an algorithm to convert it to hexadecimal. For negative integer, two’s complement method is used.Note:All letters in hexadecimal (a-f) must be in lowercase.The hexade原创 2017-02-18 16:03:20 · 327 阅读 · 0 评论 -
415. Add Strings | 大整数相加
Given two non-negative integers num1 and num2 represented as string, return the sum of num1 and num2.Note:The length of both num1 and num2 is Both num1 and num2 contains only digits 0-9.原创 2017-02-18 13:08:24 · 790 阅读 · 0 评论 -
232. Implement Queue using Stacks | 用栈实现队列的功能
Implement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue.pop() -- Removes the element from in front of queue.peek() -- Get the front element.empty(原创 2017-02-27 20:09:17 · 266 阅读 · 0 评论