LeetCode180——连续出现的数字

版权声明:我的GitHub:https://github.com/617076674。真诚求星! https://blog.csdn.net/qq_41231926/article/details/86549868

我的LeetCode代码仓:https://github.com/617076674/LeetCode

原题链接:https://leetcode-cn.com/problems/consecutive-numbers/description/

题目描述:

知识点:多表联查

思路:三表联查

由于使用交叉连接查询,返回的是笛卡尔积形式,会返回3个一样的满足条件的数据,我们需要用DISTINCT关键字来去重。

时间复杂度是O(n),其中n为Logs表中的记录数。

SQL语句:

SELECT DISTINCT l1.Num AS ConsecutiveNums FROM Logs AS l1, Logs AS l2, Logs AS l3 WHERE l1.Id = l2.Id - 1 AND l2.Id = l3.Id - 1 AND l1.Num = l2.Num AND l2.Num = l3.Num;

LeetCode解题报告:

猜你喜欢

转载自blog.csdn.net/qq_41231926/article/details/86549868