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

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

题目描述:

LeetCode180——连续出现的数字

知识点:多表联查

思路:三表联查

由于使用交叉连接查询,返回的是笛卡尔积形式,会返回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解题报告:

LeetCode180——连续出现的数字

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-11
  • 2021-07-20
  • 2022-12-23
  • 2021-09-01
  • 2022-12-23
  • 2021-08-31
猜你喜欢
  • 2022-12-23
  • 2021-07-01
  • 2021-09-30
  • 2022-12-23
  • 2021-11-23
  • 2021-04-28
  • 2022-12-23
相关资源
相似解决方案