当前位置:网站首页>Leetcode 2194. Excel 錶中某個範圍內的單元格(可以,已解决)
Leetcode 2194. Excel 錶中某個範圍內的單元格(可以,已解决)
2022-06-12 16:30:00 【我不是蕭海哇~~~~】

Excel 錶中的一個單元格 (r, c) 會以字符串 “” 的形式進行錶示,其中:
- 即單元格的列號 c 。用英文字母錶中的 字母 標識。 例如,第 1 列用 'A' 錶示,第 2 列用 'B' 錶示,第 3 列用 'C' 錶示,以此類推。
- 即單元格的行號 r 。第 r 行就用 整數 r 標識。
給你一個格式為 “:” 的字符串 s ,其中 錶示 c1 列, 錶示 r1 行, 錶示 c2 列, 錶示 r2 行,並滿足 r1 <= r2 且 c1 <= c2 。
找出所有滿足 r1 <= x <= r2 且 c1 <= y <= c2 的單元格,並以列錶形式返回。單元格應該按前面描述的格式用 字符串 錶示,並以 非遞减 順序排列(先按列排,再按行排)。
示例 1:

輸入:s = "K1:L2"
輸出:["K1","K2","L1","L2"]
解釋:
上圖顯示了列錶中應該出現的單元格。
紅色箭頭指示單元格的出現順序。
示例 2:

輸入:s = "A1:F1"
輸出:["A1","B1","C1","D1","E1","F1"]
解釋:
上圖顯示了列錶中應該出現的單元格。
紅色箭頭指示單元格的出現順序。
提示:
- s.length == 5
- ‘A’ <= s[0] <= s[3] <= ‘Z’
- ‘1’ <= s[1] <= s[4] <= ‘9’
- s 由大寫英文字母、數字、和 ‘:’ 組成
Code:
class Solution {
public:
vector<string> cellsInRange(string s) {
int start=s[1]-'0';
int end=s[4]-'0';
vector<string>res;
for(int j=s[0];j<=s[3];j++)
{
string temp;
for(int i=start;i<=end;i++)
{
temp+=j;
temp+=to_string(i);
// cout<<temp<<endl;
res.push_back(temp);
temp="";
}
}
return res;
}
};
边栏推荐
- Interview: difference between '= =' and equals()
- 【BSP视频教程】BSP视频教程第17期:单片机bootloader专题,启动,跳转配置和调试下载的各种用法(2022-06-10)
- JS monitors whether the user opens the screen focus
- acwing795 前缀和(一维)
- 33-【go】Golang sync. Usage of waitgroup - ensure that the go process is completed before the main process exits
- 面试:‘==‘与equals()之间的区别
- Project training of Shandong University rendering engine system (VII)
- Why is your next computer a computer? Explore different remote operations
- CAS乐观锁
- acwing794 高精度除法
猜你喜欢

MySQL interview arrangement

双写一致性问题

Thread pool execution process

Servlet API

acwing 803. 区间合并

Batch --03---cmdutil

Large scale real-time quantile calculation -- a brief history of quantitative sketches

Acwing788. number of reverse order pairs

generate pivot data 0

Kill program errors in the cradle with spotbugs
随机推荐
calibration of sth
Global and Chinese market of medical ECG telemetry equipment 2022-2028: Research Report on technology, participants, trends, market size and share
Gopher to rust hot eye grammar ranking
【BSP视频教程】BSP视频教程第17期:单片机bootloader专题,启动,跳转配置和调试下载的各种用法(2022-06-10)
acwing796 子矩阵的和
WebRTC 的音频网络对抗概述
The C Programming Language(第 2 版) 笔记 / 8 UNIX 系统接口 / 8.5 实例(fopen 和 getc 函数的实现)
The C Programming Language(第 2 版) 笔记 / 8 UNIX 系统接口 / 8.3 open、creat、close、unlink
使用 .NET 升级助手将NET Core 3.1项目升级为.NET 6
MongoDB系列之SQL和NoSQL的区别
"Shandong University project training" rendering engine system (8-END)
acwing 798二维差分(差分矩阵)
AssertJ 的异常(Exception )断言
The C Programming Language(第 2 版) 笔记 / 7 输入与输出 / 7.8 其它函数
acwing 800. Target and of array elements
The C Programming Language(第 2 版) 笔记 / 8 UNIX 系统接口 / 8.1 文件描述符
Analysis of Nacos config dynamic refresh source code
How to construct PostgreSQL error codes
Page class of puppeter
34-【go】Golang channel知识点