当前位置:网站首页>day500:键盘行
day500:键盘行
2022-06-22 09:18:00 【浅浅望】
问题: 键盘行
给你一个字符串数组 words ,只返回可以使用在 美式键盘 同一行的字母打印出来的单词。键盘如下图所示。
美式键盘 中:
第一行由字符 “qwertyuiop” 组成。
第二行由字符 “asdfghjkl” 组成。
第三行由字符 “zxcvbnm” 组成。
示例 1:
输入:words = [“Hello”,“Alaska”,“Dad”,“Peace”]
输出:[“Alaska”,“Dad”]
示例 2:
输入:words = [“omk”]
输出:[]
示例 3:
输入:words = [“adsdf”,“sfd”]
输出:[“adsdf”,“sfd”]
来源:力扣(LeetCode)
思路一:分行
- 不同字母标记行号;
- 遍历字符串数组中每个单词的字符,检查是否属于同一行。
class Solution {
public String[] findWords(String[] words) {
ArrayList<String> ans = new ArrayList();
String row = "23321222122233111121131313";
for(String word :words){
boolean isValid = true;
char idx = row.charAt(word.toLowerCase().charAt(0)-'a');
for(int i=1; i<word.length(); i++){
if(row.charAt(word.toLowerCase().charAt(i)-'a') != idx){
isValid = false;
break;
}
}
if(isValid)
ans.add(word);
}
int size = ans.size();
String[] arr = (String[])ans.toArray(new String[size]);
return arr;
}
}
边栏推荐
- scnprintf和snprintf的区别
- try/finally --return那些事
- Byte/byte? Don't get dizzy!
- How C processes use non static methods
- simple_strtoull字符转换相关函数
- Brush questions in C language | output 6 decimal places with%f control character (17)
- Mapping multiple exit servers on ENSP
- cocoscreator编译报错记录 Could not write cache value 。。。.gradle\daemon\4.10.3\regi
- Stream stream creation_ Operation_ Collection_ case
- Find the size of cosine
猜你喜欢

微服务架构概述

Value (address) transmission, see the name clearly, don't fall into the ditch

DHCP中继代理

Machine learning | nltk_ Data download error |nltk's stopwords corpus download error solution

性能优化专题

5 interview questions, grasp the underlying principle of string!

Shengdun technology joined dragon lizard community to build a new open source ecosystem

架设多个web站点

Binary String
![[network security officer] an attack technology that needs to be understood - high hidden and high persistent threats](/img/c9/c0ee95e816cac698f5397cc369d9ec.jpg)
[network security officer] an attack technology that needs to be understood - high hidden and high persistent threats
随机推荐
The difference between scnprintf and snprintf
Sound and shadow 2022 heavy release! Detailed explanation of the new functions of Huisheng Huiying 2022
Common SQL statements in MySQL
架设多个web站点
Double machine hot standby of firewall on ENSP
微服务架构概述
[node] theory + practice enables you to win sessions and cookies
一个老开源人的自述-如何干好开源这件事
嵌入式开发专业术语概念汇总
Audio and video 2022 beauty function introduction teach you to play video beauty
DHCP Relay
看看volatile你深知多少
两个线程各执行100次i++,得到的可能值
通过docker安装mysql(5.7+8.0)并配置主从复制(GTID+增强半同步)
Philosopher‘s Walk Gym 分治+分形
container_of
HDU - 7072 双端队列+对顶
Brush questions in C language | output love (14) with putchar
cocoscreator编译报错记录 Could not write cache value 。。。.gradle\daemon\4.10.3\regi
Try/finally --return those things