当前位置:网站首页>Leetcode- keyboard line - simple
Leetcode- keyboard line - simple
2022-06-13 05:49:00 【AnWenRen】
title :500 Keyboard line - Simple
subject
Here's an array of strings
words
, Returns only those that can be used in American keyboard Words printed with letters on the same line .
- The first line consists of the characters
"qwertyuiop"
form .- The second line consists of characters
"asdfghjkl"
form .- The third line consists of the characters
"zxcvbnm"
form .
Example 1
Input :words = ["Hello","Alaska","Dad","Peace"]
Output :["Alaska","Dad"]
Example 2
Input :words = ["omk"]
Output :[]
Example 3
Input :words = ["adsdf","sfd"]
Output :["adsdf","sfd"]
Tips
1 <= words.length <= 20
1 <= words[i].length <= 100
words[i]
By the English letters ( Lower and upper case letters ) form
Code Java
public String[] findWords(String[] words) {
StringBuilder ans = new StringBuilder();
int[] rows = {
2,3,3,2,1,2,2,2,1,2,2,2,3,3,1,1,1,1,2,1,1,3,1,3,1,3};
int index;
for (int i = 0; i < words.length; i++) {
String s = words[i].toLowerCase();
int count = rows[s.charAt(0) - 97];
int j;
for (j = 0; j < s.length(); j++) {
index = s.charAt(j) - 97;
if (rows[index] != count)
break;
}
if (j == s.length()) {
ans.append(words[i]);
ans.append("-");
}
}
String[] str = ans.toString().split("-");
if (str[0].length() == 0) {
String[] strNull = new String[0];
return strNull;
}
return str;
}
边栏推荐
- Windbos common CMD (DOS) command set
- How to set the import / export template to global text format according to the framework = (solve the problem of scientific counting)
- 2 first experience of drools
- Explanation of sentinel series' features, composition and deployment
- NVIDIA Jetson nano/xavier NX capacity expansion tutorial
- Quartz database storage
- Hainan University Postgraduate Entrance Examination electronic information (085400) landing experience
- Sentinel series integrates Nacos and realizes dynamic flow control
- Ffmpeg download suffix is Video files for m3u8
- Power of leetcode-4 - simple
猜你喜欢
NVIDIA Jetson nano/xavier NX capacity expansion tutorial
2021.9.30 learning log -postman
MySQL performs an inner join on query. The query result is incorrect because the associated fields have different field types.
Hainan University Postgraduate Entrance Examination electronic information (085400) landing experience
arrayList && linkedList
Etcd understanding of microservice architecture
How slow is the application system on tongweb? How dead is it?
Four shardingsphere JDBC sharding strategies
MongoDB 多字段聚合Group by
Feel the power of shardingsphere JDBC through the demo
随机推荐
Etcd understanding of microservice architecture
Sentinel series introduction to service flow restriction
About Evaluation Metrics
10 signalstartevent and signalcatchingevent of flowable signal events
OpenGL mosaic (VIII)
Unity game optimization [Second Edition] learning record 6
Difference between deviation and variance in deep learning
Mongodb Multi - field Aggregation group by
Config server configuration center of Nacos series
No assessment summary
11 signalthrowingevent and signalboundaryevent of flowable signal event
How to view tongweb logs correctly?
NVIDIA Jetson nano/xavier NX capacity expansion tutorial
Sentinel series integrates Nacos and realizes dynamic flow control
Nacos series registry principle and source code analysis
Ffmpeg download suffix is Video files for m3u8
= = relation between int and integer
ffmpeg 下载后缀为.m3u8的视频文件
Etcd fast cluster building
2021.9.29 learning log restful architecture