当前位置:网站首页>力扣2326、197
力扣2326、197
2022-07-31 23:46:00 【小唐学姐】
197,SQL查询
表: Weather
+---------------+---------+ | Column Name | Type | +---------------+---------+ | id | int | | recordDate | date | | temperature | int | +---------------+---------+ id 是这个表的主键 该表包含特定日期的温度信息
编写一个 SQL 查询,来查找与之前(昨天的)日期相比温度更高的所有日期的 id 。
返回结果 不要求顺序 。
查询结果格式如下例。
示例 1:
输入:
Weather 表:
+----+------------+-------------+
| id | recordDate | Temperature |
+----+------------+-------------+
| 1 | 2015-01-01 | 10 |
| 2 | 2015-01-02 | 25 |
| 3 | 2015-01-03 | 20 |
| 4 | 2015-01-04 | 30 |
+----+------------+-------------+
输出:
+----+
| id |
+----+
| 2 |
| 4 |
+----+
解释:
2015-01-02 的温度比前一天高(10 -> 25)
2015-01-04 的温度比前一天高(20 -> 30)select a.id from Weather as a, Weather as b
where to_days(a.recordDate)=to_days(b.recordDate)+1 and a.Temperature>b.Temperature2326(关于链表的移动)
给你两个整数:m 和 n ,表示矩阵的维数。
另给你一个整数链表的头节点 head 。
请你生成一个大小为 m x n 的螺旋矩阵,矩阵包含链表中的所有整数。链表中的整数从矩阵 左上角 开始、顺时针 按 螺旋 顺序填充。如果还存在剩余的空格,则用 -1 填充。
返回生成的矩阵。
示例 1:
输入:m = 3, n = 5, head = [3,0,2,6,8,1,7,9,4,2,5,5,0]
输出:[[3,0,2,6,8],[5,0,-1,-1,1],[5,2,4,9,7]]
解释:上图展示了链表中的整数在矩阵中是如何排布的。
注意,矩阵中剩下的空格用 -1 填充。
示例 2:
输入:m = 1, n = 4, head = [0,1,2]
输出:[[0,1,2,-1]]
解释:上图展示了链表中的整数在矩阵中是如何从左到右排布的。
注意,矩阵中剩下的空格用 -1 填充。
来源:力扣(LeetCode)
链接:https://leetcode.cn/problems/spiral-matrix-iv
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode() {}
* ListNode(int val) { this.val = val; }
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
* }
*/
class Solution {
public int[][] spiralMatrix(int m, int n, ListNode head) {
// 1. 创建新数组,默认全部填充 -1
int [][] arr = new int[m][n];
for(int i= 0;i<m;i++){
for(int j=0;j<n;j++){
arr[i][j]=-1;
}
}
// 2. 定义边界
int left=0, top=0,right=n-1,bottom=m-1;
// 3. 遍历链表,填充数据(结束条件: 左边界大于右边界或者上边界大于下边界)
while(!(right<left||bottom<top)){
// 3.1 →
if(left <=right && top <= bottom) {
// 如果top大于bottom,则说明最后一个横行已经填充完成,结束,如果不结束会又反着 ← 回来
for(int i =left;i<=right;i++){
if(head==null) return arr;
arr[top][i]=head.val;
head=head.next;
}
// 上边界下移
top++;
}
// 3.2 ↓
if(top <= bottom&&left<=right) {
for(int i =top;i<=bottom;i++){
if(head==null) return arr;
arr[i][right]=head.val;
head=head.next;
}
// 右边界左移
right--;
}
// 3.3 ←
if(left <=right && top <= bottom) {
for(int i =right;i>=left;i--){
if(head==null) return arr;
arr[bottom][i]=head.val;
head=head.next;
}
// 下边界上移
bottom--;
}
// 3.4 ↑
if(top <= bottom&&left<=right) {
for(int i =bottom;i>=top;i--){
if(head==null) return arr;
arr[i][left]=head.val;
head=head.next;
}
// 左边界右移
left++;
}
}
return arr;
}
}边栏推荐
- IPD process terminology
- Program processes and threads (concurrency and parallelism of threads) and basic creation and use of threads
- MLP神经网络,GRNN神经网络,SVM神经网络以及深度学习神经网络对比识别人体健康非健康数据
- C# Rectangle基本用法和图片切割
- The difference between /usr/local/bin and /usr/bin
- vim的基本使用-底行模式
- thymeleaf iterates the map collection
- The difference between adding or not adding the ref keyword when a variable of reference type is used as a parameter in a method call in C#
- 消息队列消息存储设计(架构实战营 模块八作业)
- 2022年CSP-J1 CSP-S1 第1轮初赛 报名指南
猜你喜欢
Mysql environment installation under Linux (centos)

基于单片机GSM的防火防盗系统的设计

Shell常用脚本:Nexus批量上传本地仓库增强版脚本(强烈推荐)

SVN server construction + SVN client + TeamCity integrated environment construction + VS2019 development

Payment module implementation

One line of code to solve CoreData managed object properties change in SwiftUI problem of animation effects

【1161. 最大层内元素和】

Network security - crack WiFi through handshake packets (detailed tutorial)

2022-07-31:给出一个有n个点,m条有向边的图, 你可以施展魔法,把有向边,变成无向边, 比如A到B的有向边,权重为7。施展魔法之后,A和B通过该边到达彼此的代价都是7。 求,允许施展一次魔法

cobaltstrike
随机推荐
EntityFramework保存到SQLServer 小数精度丢失
2022年CSP-J1 CSP-S1 第1轮初赛 报名指南
22年8月推广大使额外奖励规则
PHP三元(三目)运算符
消息队列消息存储设计(架构实战营 模块八作业)
如何设计高可用高性能中间件 - 作业
SQL injection Less46 (injection after order by + rand() Boolean blind injection)
NgRx 里 first 和 take(1) 操作符的区别
「SDOI2016」征途 题解
Mysql environment installation under Linux (centos)
MLP神经网络,GRNN神经网络,SVM神经网络以及深度学习神经网络对比识别人体健康非健康数据
vim的基本使用-命令模式
Shell common script: Nexus batch upload local warehouse script
Advanced Algebra _ Proof _ Any matrix is similar to an upper triangular matrix
Interview Question: Implementing Deadlocks
"APIO2010" Patrol Problem Solution
Google Earth Engine——Error: Image.clipToBoundsAndScale, argument ‘input‘: Invalid type的错误解决
Keil nRF52832下载失败
"SDOI2016" Journey Problem Solution
编程语言是什么