当前位置: 首页 > news >正文

力扣之603.连续空余座位

文章目录

  • 1. 603.连续空余座位
    • 1.1 题干
    • 1.2 准备数据
    • 1.3 思路分析
    • 1.4 解法
    • 1.5 结果截图

1. 603.连续空余座位

1.1 题干

表: Cinema

±------------±-----+
| Column Name | Type |
±------------±-----+
| seat_id | int |
| free | bool |
±------------±-----+
Seat_id 是该表的自动递增主键列。
在 PostgreSQL 中,free 存储为整数。请使用 ::boolean 将其转换为布尔格式。
该表的每一行表示第 i 个座位是否空闲。1 表示空闲,0 表示被占用。

查找电影院所有连续可用的座位。

返回按 seat_id 升序排序 的结果表。

测试用例的生成使得两个以上的座位连续可用。

结果表格式如下所示。

示例 1:

输入:
Cinema 表:
±--------±-----+
| seat_id | free |
±--------±-----+
| 1 | 1 |
| 2 | 0 |
| 3 | 1 |
| 4 | 1 |
| 5 | 1 |
±--------±-----+
输出:
±--------+
| seat_id |
±--------+
| 3 |
| 4 |
| 5 |
±--------+

1.2 准备数据

Create table If Not Exists Cinema (seat_id int primary key auto_increment, free bool)
Truncate table Cinema
insert into Cinema (seat_id, free) values ('1', '1')
insert into Cinema (seat_id, free) values ('2', '0')
insert into Cinema (seat_id, free) values ('3', '1')
insert into Cinema (seat_id, free) values ('4', '1')
insert into Cinema (seat_id, free) values ('5', '1')

1.3 思路分析

在这里插入图片描述

1.4 解法

select distinct c2.seat_id from Cinema c1,Cinema c2 where abs(c1.seat_id-c2.seat_id)=1 and c1.free=1 and c2.free=1;

1.5 结果截图

在这里插入图片描述


http://www.mrgr.cn/news/45525.html

相关文章:

  • java高并发的使用
  • 【NLP】GRU基本结构原理,代码实现
  • Flutter + Three.js (WebView)实现桌面端3d模型展示和交互
  • 【Vue】Vue2(2)
  • 【LeetCode刷题】:双指针篇(移动零、复写零)
  • SEO(搜索引擎优化)指南
  • 红队老子养成记2 - 不想渗透pc?我们来远控安卓!(全网最详细)
  • 要实现无限极评论
  • 计算机毕业设计-自主完成指南
  • MySql复习知识及扩展内容
  • C语言从头学65—学习头文件 <stdio.h>(一)
  • 碧桂园服务携手安徽砀山,以购代捐助力乡村振兴
  • scaling 的作用
  • Python Kivy 完整应用开发:待办事项列表
  • 【RTCP】Interarrival Jitter: 到达间隔抖动的举例说明
  • 【Transformer 模型中的投影层,lora_projection是否需要?】
  • 点餐小程序实战教程17角色管理
  • OpenHarmony(鸿蒙南向开发)——轻量系统内核(LiteOS-M)【内存调测】
  • Ngx+Lua+Redis 快速存储POST数据
  • 如何使用PSTools工具集中的PSExec修改注册表信息,解决某些注册表项无法删除的问题