当前位置:网站首页>力扣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.Temperature
2326(关于链表的移动)
给你两个整数: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;
}
}
边栏推荐
- Components of TypeScript
- Keil nRF52832 download failed
- 【Acwing】The 62nd Weekly Game Solution
- 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#
- I don't know what to do with sync issues
- 22年8月推广大使额外奖励规则
- How to import a Golang external package and use it?
- 10大主流3D建模技术
- 面试题:实现死锁
- Daily--Kali opens SSH (detailed tutorial)
猜你喜欢
嵌入式开发没有激情了,正常吗?
Shell常用脚本:Nexus批量上传本地仓库脚本
编译型语言和解释型语言的区别
【Acwing】The 62nd Weekly Game Solution
硬件设备计算存储及数据交互杂谈
Document management and tools in the development process
[MATLAB project combat] LDPC-BP channel coding
新产品如何进行网络推广?
Mysql environment installation under Linux (centos)
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#
随机推荐
The role of /etc/resolv.conf
Pytest first experience
SQL注入 Less47(报错注入) 和Less49(时间盲注)
助力数字政府建设,中科三方构建域名安全保障体系
mysql having的用法
"APIO2010" Patrol Problem Solution
编写方法将一个数组扁平化并且去重和递增排序
游戏安全03:缓冲区溢出攻击简单解释
Difference between first and take(1) operators in NgRx
cobaltstrike
基于simulink的Active anti-islanding-AFD主动反孤岛模型仿真
如何撰写出一篇优质的数码类好物推荐文
Drawing process of hand-drawn map of scenic spots
命名实体识别-模型:BERT-MRC
【读书笔记->数据分析】02 数据分析准备
NgRx 里 first 和 take(1) 操作符的区别
网易云信圈组上线实时互动频道,「破冰」弱关系社交
Fixed-length usage of nanopb string type based on RT1052 Aworks (27)
The difference between /usr/local/bin and /usr/bin
@JsonFormat(pattern=“yyyy-MM-dd“)时间差问题