当前位置:网站首页>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;
}
}
边栏推荐
猜你喜欢

Overview of microservice architecture

Fuzzy query and aggregate function

5 interview questions, grasp the underlying principle of string!

File expert ---multer
![[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

It is hoped that more and more women will engage in scientific and technological work

锁-ReentrantLock

Threejs implementation of simple panoramic view demo

Mapping Multi - export Server on ENSP

在ensp上做多出口服務器映射
随机推荐
Summary and future prospect of transfer learning | community essay solicitation
Function summary (1)
container_of
IS_ ERR()
论文笔记:DETR: End-to-End Object Detection with Transformers (from 李沐老师and朱老师)
simple_ Strtoull character conversion related functions
container_ of
一文走近ZMQ
Typical cases of final
架设多个web站点
经典&&案例
支付-订单案例构建
值(址)传递,看清名字,别掉沟里
[node] node+ SMS API to realize verification code login
一个老开源人的自述-如何干好开源这件事
copy_from_user和copy_to_user
嵌入式开发专业术语概念汇总
Final典型案例
C language question brushing | three item operation to realize capital judgment (16)
[network security officer] an attack technology that needs to be understood - high hidden and high persistent threats