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. signal(SIGPIPE, SIG_IGN) (转)

    signal(SIGPIPE, SIG_IGN) 当服务器close一个连接时,若client端接着发数据. 根据TCP 协议的规定,会收到一个RST响应,client再往这个服务器发送数据时,系统会 ...

  2. IS支持解析json

    1. MIME设置:在IIS的站点属性的HTTP头设置里,选MIME 映射中点击”文件类型”-”新类型”,添加一个文件类型:关联扩展名:*.json内容类型(MIME):application/x-j ...

  3. 利用层的table-row、table-cell属性进行页面布局

    利用层的table-row.table-cell属性可以进行等高.宽度自适应页面布局,这是参看了<我所知道的几种display:table-cell的应用>及<基于display:t ...

  4. TensorFlow基础笔记(0) tensorflow的基本数据类型操作

    import numpy as np import tensorflow as tf #build a graph print("build a graph") #生产变量tens ...

  5. Spring 4 官方文档学习(十)数据访问之DAO支持

    1.介绍 Spring 中 Data Access Object (DAO)支持 的目标是以一种一致的方式更简单的使用JDBC.Hibernate.JPA或JDO等数据访问技术.可以在前面说的几种数据 ...

  6. css -- css选择器

    选择器 例子 例子描述 CSS .class .intro 选择 class="intro" 的所有元素. 1 #id #firstname 选择 id="firstna ...

  7. VC++ : GetIDsOfNames 调用失败,获取的dispid为-1

    今天调试自己的程序,需要调用一个COM组件中的方法,利用GetIDsOfNames获取调用函数对象的DISPID. GetIDsOfNames: 把COM接口的方法名字和参数(可选)映射成一组DISP ...

  8. 在VS中安装/使用 MVVMLight

    一般来说,我喜欢使用NuGet来获取这些东西,比如Newtonsoft.Json.netlog4.MVVMLight 之类的东西.至于NuGet的使用,以后再说吧.为了直接进入正题,我们这里直接使用V ...

  9. NYOJ467 中缀式变后缀式 【栈】

    中缀式变后缀式 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描写叙述 人们的日常习惯是把算术表达式写成中缀式,但对于机器来说更"习惯于"后缀式.关于算术 ...

  10. swift - UIAlertView 的用法

    1,创建一个alertview,并带有“确定”和“取消”两个按钮 (注:在这里使用alertview,会报警告,那是因为从ios 8 以后,建议使用UIAlertviewController) //警 ...