随笔分类 -  LeetCode

上一页 1 ··· 6 7 8 9 10 11 12 13 14 15 下一页
刷题
摘要:题目来源 LeetCode_46 题目描述 给定一个不含重复数字的数组 nums ,返回其 所有可能的全排列 。你可以 按任意顺序 返回答案。 示例 1: 输入: nums = [1,2,3] 输出: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]] 阅读全文
posted @ 2021-03-07 21:24 Garrett_Wale 阅读(92) 评论(0) 推荐(0)
摘要:232. 用栈实现队列 LeetCode_232 题目描述 方法一:在push时将原有栈的元素全部出栈然后再将当前元如入栈,最后再将第二个栈的元素入第一个栈 class MyQueue{ int num; Deque<Integer> sta1, sta2;//使用双端队列来模拟栈 /** Init 阅读全文
posted @ 2021-03-07 20:54 Garrett_Wale 阅读(81) 评论(0) 推荐(0)
摘要:54. 螺旋矩阵 LeetCode_54 相似题目:剑指 Offer 29. 顺时针打印矩阵 题目描述 代码实现 class Solution { public List<Integer> spiralOrder(int[][] matrix) { int m = matrix.length;//行 阅读全文
posted @ 2021-03-07 20:23 Garrett_Wale 阅读(143) 评论(0) 推荐(0)
摘要:题目来源 LeetCode_69 题目详情 题解分析 方法一:使用sqrt class Solution { public int mySqrt(int x) { return (int)Math.sqrt((double)x); } } 方法二:袖珍计算器 class Solution { pub 阅读全文
posted @ 2021-03-07 20:04 Garrett_Wale 阅读(83) 评论(0) 推荐(0)
摘要:197. 上升的温度 LeetCode_MySql_197 题目描述 代码实现 # Write your MySQL query statement below select we1.id Id from Weather we1, Weather we2 where datediff(we1.rec 阅读全文
posted @ 2021-03-06 22:45 Garrett_Wale 阅读(56) 评论(0) 推荐(0)
摘要:415. 字符串相加 LeetCode_415 题目详情 方法一:使用暴力法 class Solution { public String addStrings(String num1, String num2) { int len1 = num1.length(); int len2 = num2 阅读全文
posted @ 2021-03-06 21:44 Garrett_Wale 阅读(109) 评论(0) 推荐(0)
摘要:196. 删除重复的电子邮箱 LeetCode_MySql_196 题目描述 实现代码 # Write your MySQL query statement below # 需要找到两张表中,其他记录中具有相同邮件地址但是id更大的记录,将其删除即可 delete p1 from Person p1 阅读全文
posted @ 2021-03-06 21:22 Garrett_Wale 阅读(163) 评论(0) 推荐(0)
摘要:145. 二叉树的后序遍历 LeetCode_145 题目描述 递归解法 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; 阅读全文
posted @ 2021-03-05 18:57 Garrett_Wale 阅读(66) 评论(0) 推荐(0)
摘要:160. 相交链表 LeetCode_160 题目描述 题解分析 本题使用的方法是双指针法,题目和环形链表相似,都是利用链表的特性来求解。 当遍历链表a到达尾部时,再指向链表b的头部;当遍历链表b到末尾时,再指向链表a的头部。 再次相遇时便是相交结点。 java代码 /** * Definition 阅读全文
posted @ 2021-03-05 17:59 Garrett_Wale 阅读(76) 评论(0) 推荐(0)
摘要:185. 部门工资前三高的所有员工 LeetCode_MySql_185 题目描述 方法一:使用join on # Write your MySQL query statement below select d.Name as 'Department', e1.Name as 'Employee', 阅读全文
posted @ 2021-03-03 20:20 Garrett_Wale 阅读(122) 评论(0) 推荐(0)
摘要:5. 最长回文子串 LeetCode_5 题目详情 方法一:暴力法(超时) class Solution { public String longestPalindrome(String s) { int len = s.length(); int maxLen = 0; String result 阅读全文
posted @ 2021-03-03 19:18 Garrett_Wale 阅读(153) 评论(0) 推荐(0)
摘要:184. 部门工资最高的员工 LeetCode_MySql_184 题目描述 题解分析 1.首先需要使用group by找出工资最高的值 2. 然后考虑到最高工资的可能有多位,所以使用in语句找到所有符合条件的员工 3. 最外层使用连接连表查询员工所在的部门名字。 代码实现 # Write your 阅读全文
posted @ 2021-03-02 20:05 Garrett_Wale 阅读(90) 评论(0) 推荐(0)
摘要:183. 从不订购的客户 LeetCode_MySql_183 题目描述 代码实现 # Write your MySQL query statement below select Name as 'Customers' from Customers where Customers.Id not in 阅读全文
posted @ 2021-03-02 19:14 Garrett_Wale 阅读(49) 评论(0) 推荐(0)
摘要:182. 查找重复的电子邮箱 LeetCode_MySql_182 题目描述 方法一:使用笛卡尔积 # Write your MySQL query statement below select distinct t1.Email from Person t1, Person t2 where t1 阅读全文
posted @ 2021-03-02 18:28 Garrett_Wale 阅读(104) 评论(0) 推荐(0)
摘要:181. 超过经理收入的员工 LeetCode_MySql_181 题目描述 方法一:笛卡尔积 # Write your MySQL query statement below select e1.Name as 'Employee' from Employee e1, Employee e2 wh 阅读全文
posted @ 2021-03-02 11:12 Garrett_Wale 阅读(101) 评论(0) 推荐(0)
摘要:180. 连续出现的数字 LeetCode_MySql_180 题目描述 代码实现 # Write your MySQL query statement below select distinct t1.num as ConsecutiveNums from Logs t1, Logs t2, Lo 阅读全文
posted @ 2021-03-02 10:46 Garrett_Wale 阅读(87) 评论(0) 推荐(0)
摘要:178. 分数排名 LeetCode_MySql_178 题目描述 题解分析 排名函数 DENSE_RANK()。如果使用 DENSE_RANK() 进行排名会得到:1,1,2,3,4。 RANK()。如果使用 RANK() 进行排名会得到:1,1,3,4,5。 ROW_NUMBER()。如果使用 阅读全文
posted @ 2021-03-02 10:33 Garrett_Wale 阅读(105) 评论(0) 推荐(0)
摘要:MySql_176. 第二高的薪水 LeetCode_MySql_176 题目描述 题解分析 代码实现 # Write your MySQL query statement below select( select distinct Salary from Employee order by Sal 阅读全文
posted @ 2021-03-01 22:23 Garrett_Wale 阅读(65) 评论(0) 推荐(0)
摘要:653. 两数之和 IV - 输入 BST 题目描述 题解分析 最简单的方法就是遍历整棵树,找出所有可能的组合,判断是否存在和为 kk 的一对节点。现在在此基础上做一些改进。 如果存在两个元素之和为 k,即 x+y=k,并且已知 x 是树上一个节点的值,则只需判断树上是否存在一个值为 y 的节点,使 阅读全文
posted @ 2021-03-01 20:25 Garrett_Wale 阅读(54) 评论(0) 推荐(0)
摘要:167. 两数之和 II - 输入有序数组 LeetCode_167 题目描述 方法一:暴力法(使用哈希表) class Solution { public int[] twoSum(int[] numbers, int target) { int len = numbers.length; Has 阅读全文
posted @ 2021-03-01 18:00 Garrett_Wale 阅读(92) 评论(0) 推荐(0)

上一页 1 ··· 6 7 8 9 10 11 12 13 14 15 下一页