![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
jiang_16
一个想学好编程的弱渣妹纸,猎奇,脑洞向...
展开
-
152. Maximum Product Subarray
最大子段乘积,我会最大子段和,但是这道题我不会用DP做,呜呜呜呜(我还有救吗)。我用的方法比较简单暴力,时间复杂度O(n*n),最终OJ测试通过是356ms(其实还可以哈遍历数组,当前数为正数时直接乘同时更新最大值;为0时则置1;为负数时,需要先判断在 剩下的数组元素且在0元素之前 的负数的个数,若不再有负数则置1,若有偶数个则一直连乘到除最后一个负数,若有奇数个则连乘到最后一个元素,最后...原创 2019-12-28 10:49:49 · 208 阅读 · 0 评论 -
55. Jump Game
这几天在公司里有点咸呀,嘿嘿。闲来无事,随便做做题这是道贪心题,确定个贪心策略就完事儿了:只要没有0,就一定能过去,甭管怎么走,肯定能过去;有0的话,就往前找,只要能找到一个点的值能一下子跨过0,也就能过去,找不到就过不去~题目:Given an array of non-negative integers, you are initially positioned at the fi...原创 2019-12-26 09:40:52 · 198 阅读 · 0 评论 -
185. Department Top Three Salaries (hard)
The Employee table holds all employees. Every employee has an Id, and there is also a column for the department Id.+----+-------+--------+--------------+| Id | Name | Salary | DepartmentId |+---...原创 2019-05-21 16:46:26 · 214 阅读 · 0 评论 -
二叉树的镜像
题目描述操作给定的二叉树,将其变换为源二叉树的镜像。输入描述:二叉树的镜像定义:源二叉树 8 / \ 6 10 / \ / \ 5 7 9 11 镜像二叉树 8 / \ 10 6 / \ / \ 11 9 7 5...原创 2019-03-18 21:08:27 · 116 阅读 · 0 评论 -
调整数组顺序使奇数位于偶数前面
题目描述输入一个整数数组,实现一个函数来调整该数组中数字的顺序,使得所有的奇数位于数组的前半部分,所有的偶数位于数组的后半部分,并保证奇数和奇数,偶数和偶数之间的相对位置不变。在前面的博客中讲过这种题目,不过那道题没要求“相对位置不变”(稳定性)怎么保证相对位置不变呢,显然之前的方法已经不行了。其实最简单的方法就是移动元素,遍历数组,在遇到第一个奇数元素时把它插入数组前边,用一个变量j...原创 2019-03-18 20:15:16 · 115 阅读 · 0 评论 -
二叉搜索树的后序遍历序列
题目描述输入一个整数数组,判断该数组是不是某二叉搜索树的后序遍历的结果。如果是则输出Yes,否则输出No。假设输入的数组的任意两个数字都互不相同没给样例... 关键字:二叉搜索树,后序遍历。根在最后,前半边左子树都比根小,后半边右子树都比根大,以此递归判断class Solution {public: bool verify(vector<int> s,...原创 2019-03-21 22:46:47 · 98 阅读 · 0 评论 -
【数据结构之链表】25. Reverse Nodes in k-Group
25. Reverse Nodes in k-GroupHardGiven a linked list, reverse the nodes of a linked list k at a time and return its modified list.k is a positive integer and is less than or equal to the length o...原创 2019-02-26 22:30:58 · 134 阅读 · 0 评论 -
【数据结构之链表】LeetCode 19. Remove Nth Node From End of List
19. Remove Nth Node From End of ListMediumGiven a linked list, remove the n-th node from the end of list and return its head.Example:Given linked list: 1->2->3->4->5, and n = 2....原创 2019-02-26 19:55:18 · 206 阅读 · 0 评论 -
【数据库查询】184. Department Highest Salary
184. Department Highest SalaryMediumSQL SchemaThe Employee table holds all employees. Every employee has an Id, a salary, and there is also a column for the department Id.+----+-------+------...原创 2019-02-28 09:22:18 · 256 阅读 · 0 评论 -
【数据库查询】176. Second Highest Salary
176. Second Highest SalaryEasyWrite a SQL query to get the second highest salary from the Employee table.+----+--------+| Id | Salary |+----+--------+| 1 | 100 || 2 | 200 || 3 | 3...原创 2019-02-27 20:00:11 · 275 阅读 · 0 评论 -
【数据库查询】180. Consecutive Numbers
180. Consecutive NumbersMediumSQL SchemaWrite a SQL query to find all numbers that appear at least three times consecutively.+----+-----+| Id | Num |+----+-----+| 1 | 1 || 2 | 1 ||...原创 2019-02-27 20:47:48 · 228 阅读 · 0 评论 -
23. Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.归并排序/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *ne...原创 2018-03-04 09:01:34 · 114 阅读 · 0 评论 -
74. Search a 2D Matrix
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to right.The first integer of each row is原创 2017-12-31 11:22:45 · 131 阅读 · 0 评论 -
240. Search a 2D Matrix II
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted in ascending from left to right.Integers in each col原创 2017-12-31 11:49:12 · 168 阅读 · 0 评论 -
111. Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.求最小深度/** * Definition for a binary原创 2017-11-21 23:06:36 · 165 阅读 · 0 评论 -
542. 01 Matrix
Given a matrix consists of 0 and 1, find the distance of the nearest 0 for each cell.The distance between two adjacent cells is 1.Example 1: Input:0 0 00 1 00 0 0Output:0 0 00 1 00 0原创 2017-12-08 21:48:55 · 196 阅读 · 0 评论 -
695. Max Area of Island
Given a non-empty 2D array grid of 0's and 1's, an island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrou原创 2017-11-14 11:26:07 · 131 阅读 · 0 评论