![](https://img-blog.csdnimg.cn/20201014180756913.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
千筠Wyman
这个作者很懒,什么都没留下…
展开
-
【LeetCode】617. 合并两个二叉树
问题描述Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not.You need to merge them into a new binar...原创 2019-12-09 13:03:04 · 319 阅读 · 0 评论 -
【LeetCode】63. 不同路径 II
问题描述一个机器人位于一个 m x n 网格的左上角 (起始点在标记为“Start” )。机器人每次只能向下或者向右移动一步。机器人试图达到网格的右下角(标记为“Finish”)。现在考虑网格中有障碍物。那么从左上角到右下角将会有多少条不同的路径?网格中的障碍物和空位置分别用1和0来表示。说明:m和n的值均不超过 100。示例1:输入:[ [0,0,0], [0,1,0], [0,0,0]]输出: 2解释:3x3 网格的正中间有一个障碍物。...原创 2020-07-06 20:49:51 · 127 阅读 · 0 评论 -
【LeetCode】108. 将有序数组转换为二叉搜索树
问题描述将一个按照升序排列的有序数组,转换为一棵高度平衡二叉搜索树。本题中,一个高度平衡二叉树是指一个二叉树每个节点的左右两个子树的高度差的绝对值不超过 1。示例:给定有序数组: [-10,-3,0,5,9],一个可能的答案是:[0,-3,9,-10,null,5],它可以表示下面这个高度平衡二叉搜索树: 0 / \ -3 9 / / -10 5Java 实现既然数组是有序的,构建平衡二叉树时利用二分思想就很好实现了。树的构建.原创 2020-07-03 22:40:02 · 142 阅读 · 0 评论 -
【剑指 Offer】09. 用两个栈实现队列
问题描述用两个栈实现一个队列。队列的声明如下,请实现它的两个函数 appendTail 和 deleteHead ,分别完成在队列尾部插入整数和在队列头部删除整数的功能。(若队列中没有元素,deleteHead操作返回 -1 )。其中:1 <= values <= 10000 最多会对appendTail、deleteHead 进行10000次调用示例 1:输入:["CQueue","appendTail","deleteHead","deleteHead"][...原创 2020-06-30 20:47:48 · 302 阅读 · 0 评论 -
【LeetCode】238. 除去自身后,数组各项的乘积
问题描述Given an array nums of n integers where n > 1, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Constraint: It's guaranteed tha...原创 2020-04-16 14:11:42 · 292 阅读 · 0 评论 -
【LeetCode】347. 前K个频繁出现的元素
问题描述Given a non-empty array of integers, return thekmost frequent elements.Note:You may assumekis always valid, 1 ≤k≤ number of unique elements. Your algorithm's time complexitymust beb...原创 2020-04-08 14:34:45 · 255 阅读 · 0 评论 -
【LeetCode】647. 回文子串
问题描述Given a string, your task is to count how many palindromic substrings in this string.The substrings with different start indexes or end indexes are counted as different substrings even they co...原创 2020-04-08 14:05:50 · 277 阅读 · 0 评论 -
【LeetCode】22. 生成括号
问题描述Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.给定n对括号,编写一个函数来生成所有形式良好的括号组合。比如,给定 n = 3,则输出结果应为:[ "((()))", "(()())", "(())()"...原创 2020-04-05 10:47:00 · 166 阅读 · 0 评论 -
【LeetCode】46. 排列
问题描述Given a collection ofdistinctintegers, return all possible permutations.给定一组不同的整数,返回所有可能的排列。输入: [1,2,3]输出:[ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1]]Python...原创 2020-04-05 10:49:14 · 120 阅读 · 0 评论 -
【LeetCode】94. 二叉树中序遍历
问题描述Given a binary tree, return theinordertraversal of its nodes' values.Follow up:Recursive solution is trivial, could you do it iteratively?给定一个二叉树,返回其节点值的顺序遍历。后续工作:递归解决方案很简单,可以迭代地解决吗?输...原创 2020-01-15 14:02:52 · 121 阅读 · 0 评论 -
【LeetCode】739. 每日温度
问题描述Given a list of daily temperaturesT, return a list such that, for each day in the input, tells you how many days you would have to wait until a warmer temperature. If there is no future day for...原创 2020-01-14 12:38:24 · 196 阅读 · 0 评论 -
【LeetCode】406. 根据身高重建队列
问题描述Suppose you have a random list of people standing in a queue. Each person is described by a pair of integers(h, k), wherehis the height of the person andkis the number of people in front of...原创 2020-01-09 14:44:55 · 239 阅读 · 0 评论 -
【LeetCode】338. 计算比特位的数目
问题描述Given a non negative integer numbernum. For every numbersiin the range0 ≤ i ≤ numcalculate the number of 1's in their binary representation and return them as an array.Follow up:It is v...原创 2020-01-02 20:50:26 · 170 阅读 · 0 评论 -
【LeetCode】581. 最短的无排序连续子数组
问题描述Given an integer array, you need to find onecontinuous subarraythat if you only sort this subarray in ascending order, then the whole array will be sorted in ascending order, too.You need to...原创 2020-01-02 20:04:28 · 346 阅读 · 0 评论 -
【LeetCode】160. 两个链表的交集
问题描述Write a program to find the node at which the intersection of two singly linked lists begins.Notes:If the two linked lists have no intersection at all, returnnull. The linked lists must re...原创 2020-01-01 20:58:11 · 651 阅读 · 0 评论 -
【LeetCode】234. 回文链表
问题描述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?给定一个单链表,判断它是否是回文。跟进:你能在O(n)时间和O(1)空间内实现吗?输入: 1->2输出: false输入: 1-...原创 2020-01-01 16:51:16 · 168 阅读 · 0 评论 -
【LeetCode】22. 有效的括号
问题描述Given a string containing just the characters'(',')','{','}','['and']', determine if the input string is valid.An input string is valid if:Open brackets must be closed by the same typ...原创 2020-01-01 15:27:41 · 117 阅读 · 0 评论 -
【LeetCode】141. 链表环
问题描述Given a linked list, determine if it has a cycle in it.To represent a cycle in the given linked list, we use an integerposwhich represents the position (0-indexed)in the linked list where t...原创 2019-12-24 16:48:02 · 102 阅读 · 0 评论 -
【LeetCode】155. 小栈
问题描述Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack. pop() -- Removes the element on top of the stack. top()...原创 2019-12-24 16:21:36 · 114 阅读 · 0 评论 -
【LeetCode】198. 入室偷窃
问题描述You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent...原创 2019-12-24 15:51:41 · 383 阅读 · 0 评论 -
【LeetCode】437. 路径求和(三)
问题描述You are given a binary tree in which each node contains an integer value.Find the number of paths that sum to a given value.The path does not need to start or end at the root or a leaf, but ...原创 2019-12-24 15:14:36 · 212 阅读 · 0 评论 -
【LeetCode】1. 两个数的和
问题描述Given an array of integers, returnindicesof the two numbers such that they add up to a specific target.You may assume that each input would haveexactlyone solution, and you may not use the...原创 2019-12-24 14:50:45 · 83 阅读 · 0 评论 -
【LeetCode】101. 对称树
问题描述Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).Bonus points if you could solve it both recursively and iteratively.给定一个二叉树,检查它是否是自身的镜像(即围绕其中心对称)...原创 2019-12-23 15:50:14 · 159 阅读 · 0 评论 -
【LeetCode】53. 最大子序列
问题描述Given an integer arraynums, find the contiguous subarray(containing at least one number) which has the largest sum and return its sum.If you have figured out the O(n) solution, try coding an...原创 2019-12-23 15:01:14 · 160 阅读 · 0 评论 -
【LeetCode】543. 二叉树的周长
问题描述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 thelongestpath between any two nodes in a tree. This path may or...原创 2019-12-23 14:17:10 · 241 阅读 · 0 评论 -
【LeetCode】70. 爬楼梯
问题描述You are climbing a stair case. It takesnsteps 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?Note:Givennwill be a po...原创 2019-12-23 14:11:43 · 133 阅读 · 0 评论 -
【LeetCode】121. 买入和卖出股票的最佳时间
问题描述Say you have an array for which theithelement is the price of a given stock on dayi.If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the s...原创 2019-12-10 14:12:45 · 607 阅读 · 0 评论 -
【LeetCode】21. 合并两个有序链表
问题描述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.合并两个已排序的链表,并以新链表的形式返回。新列表应该通过将前两个列表的节点拼接在一起来创建。输...原创 2019-12-10 13:34:18 · 144 阅读 · 0 评论 -
【LeetCode】169. 主要元素
问题描述Given an array of sizen, find the majority element. The majority element is the element that appearsmore than⌊ n/2 ⌋times.You may assume that the array is non-empty and the majority elemen...原创 2019-12-10 08:49:31 · 244 阅读 · 0 评论 -
【LeetCode】448. 找到数组中没有出现的元素
问题描述Given an array of integers where 1 ≤ a[i] ≤n(n= size of array), some elements appear twice and others appear once.Find all the elements of [1,n] inclusive that do not appear in this array....原创 2019-12-10 08:48:49 · 412 阅读 · 0 评论 -
【LeetCode】283. 移动所有的0元素
问题描述Given an arraynums, write a function to move all0's to the end of it while maintaining the relative order of the non-zero elements.Note:You must do thisin-placewithout making a copy of t...原创 2019-12-09 14:37:25 · 149 阅读 · 0 评论 -
【LeetCode】206. 反转一个单向链表
问题描述Reverse a singly linked list.A linked list can be reversed either iteratively or recursively. Could you implement both?反转一个单向链表。链表可以迭代或递归地反转。你能实现这两个吗?输入: 1->2->3->4->5->N...原创 2019-12-09 14:23:19 · 85 阅读 · 0 评论 -
【LeetCode】226. 左右颠倒二叉树
问题描述Invert a binary tree.颠倒一个二叉树输入: 4 / \ 2 7 / \ / \1 3 6 9输出: 4 / \ 7 2 / \ / \9 6 3 1Python 实现# Definition for a binary tree node.# ...原创 2019-12-09 13:46:48 · 197 阅读 · 0 评论 -
【LeetCode】136. 单个的数字
问题描述Given anon-emptyarray of integers, every element appearstwiceexcept for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it with...原创 2019-12-09 13:37:49 · 99 阅读 · 0 评论 -
【LeetCode】104. 二叉树的最大深度
问题描述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.Note:A leaf is a node with no c...原创 2019-12-09 13:12:16 · 125 阅读 · 0 评论