Description:

Write a SQL query to find all numbers that appear at least three times consecutively.

+----+-----+
| Id | Num |
+----+-----+
| 1 | 1 |
| 2 | 1 |
| 3 | 1 |
| 4 | 2 |
| 5 | 1 |
| 6 | 2 |
| 7 | 2 |
+----+-----+

For example, given the above Logs table, 1 is the only number that appears consecutively for at least three times.

要查出连续至少出现3次的Num。需要3个循环套一起,但是时间复杂度是O(n),因为每个循环实际上只遍历了一次。

# Write your MySQL query statement below
select DISTINCT(l1.Num)
from Logs l1, Logs l2, Logs l3
where l1.Id+1=l2.Id and l1.Id+2=l3.Id and l1.Num=l2.Num and l1.Num=l3.Num;

LeetCode——Consecutive Numbers的更多相关文章

  1. [LeetCode] Consecutive Numbers 连续的数字 --数据库知识(mysql)

    1. 题目名称   Consecutive Numbers 2 .题目地址 https://leetcode.com/problems/consecutive-numbers/ 3. 题目内容 写一个 ...

  2. [LeetCode] Consecutive Numbers 连续的数字

    Write a SQL query to find all numbers that appear at least three times consecutively. +----+-----+ | ...

  3. leetcode Database3(Nth Highest Salary<—>Consecutive Numbers<—>Department Highest Salary)

    一.Nth Highest Salary Write a SQL query to get the nth highest salary from the Employee table. +----+ ...

  4. LeetCode Database: Consecutive Numbers

    Consecutive Numbers Write a SQL query to find all numbers that appear at least three times consecuti ...

  5. 【leetcode】1296. Divide Array in Sets of K Consecutive Numbers

    题目如下: Given an array of integers nums and a positive integer k, find whether it's possible to divide ...

  6. [LeetCode] 829. Consecutive Numbers Sum 连续数字之和

    Given a positive integer N, how many ways can we write it as a sum of consecutive positive integers? ...

  7. 【LeetCode】829. Consecutive Numbers Sum 解题报告(C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 数学方法 日期 题目地址:https://leetc ...

  8. [LeetCode#180]Consecutive Numbers

    Write a SQL query to find all numbers that appear at least three times consecutively. +----+-----+ | ...

  9. 829. Consecutive Numbers Sum

    Given a positive integer N, how many ways can we write it as a sum of consecutive positive integers? ...

随机推荐

  1. invalid conversion from 'void* (*)()' to 'void* (*)(void*)'

    void *thread1() ], NULL, thread1, NULL)) != ) 提示:invalid conversion from 'void* (*)()' to 'void* (*) ...

  2. find 命令一个命令多参数如何使用,????,perm

    [root@ob2 mytmp]# find -mtime -7 -type f \( -name "*.html" -o -name "*.tar.gz" \ ...

  3. 利用Nginx搭建RTMP视频直播,点播服务器,ffmpeg推流,回看

        一.环境和工具 ubuntu 14.04 desktop 不用server的原因是一部分的演示用到了linux视频播放和直播软件,自己还要装桌面,麻烦. 不建议使用 最新的16TLS,我一开始 ...

  4. EasyUI的treegrid组件动态加载数据问题的解决办法

    http://www.jquerycn.cn/a_3455 —————————————————————————————————————————————————————————————————————— ...

  5. r语言,安装外部包 警告: 无法将临时安装

    安装R语言中的外部包时,出现错误提示 试开URL’https://mirrors.tuna.tsinghua.edu.cn/CRAN/bin/windows/contrib/3.3/ggplot2_2 ...

  6. Windows通用知识讲解一

    Window应用程序的类型 --控制台程序Console DOS程序,本身没有窗口,通过Windows DOS窗口执行 --窗口程序 拥有自己的窗口,可以与用户交互 --库程序 存放代码.数据的程序, ...

  7. 关于Android中Fragment静态和动态加载的方法

    一.静态加载 1.首先创建一个layout布局fragment.xml,里面放要显示和操作的控件 2.创建一个layout布局main1.xml,用来实现页面的跳转(跳转为要实现静态加载的界面) 3. ...

  8. wex5中集成的mysql数据库 打开时一闪而过 报错

    在进程中kill mysql.exe 重新启动即可

  9. Android ListView 笔记

    ListView以列表的形式展示数据内容. 布局文件如下所示,添加一个ListView. activity_main.xml <?xml version="1.0" enco ...

  10. debian下系列下的apt-get 命令与deb包的手动安装的dpkg命令

    手动下载的deb包的相关操作: 操作deb 使用dpkg 命令工具, dpkg 是Debian package的简写. 下面列举常用的 操作: dpkg –I name.deb  查看 包的详细信息( ...