当前位置:网站首页>Force deduction question 500, keyboard line, JS implementation
Force deduction question 500, keyboard line, JS implementation
2022-07-06 22:04:00 【Big chicken legs are best】
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 keyboard is shown in the figure below .
American keyboard in :
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 .
source : Power button (LeetCode)
link :https://leetcode-cn.com/problems/keyboard-row
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
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"]
source : Power button (LeetCode)
link :https://leetcode-cn.com/problems/keyboard-row
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
### Their thinking
Here is the solution
On the keyboard 3 Rows correspond to each other 3 An array
2 Secondary cycle , Take out each word for the first time, turn them into lowercase and then into array
The first word corresponds to which array it belongs
Start the second cycle if there is a letter of the word that does not belong to the array
Just exit the loop , Don't add the word to the array
### Code
```javascript
/**
* @param {string[]} words
* @return {string[]}
*/
var findWords = function(words) {
let a=['q','w','e','r','t','y','u','i','o','p']
let b=['a','s','d','f','g','h','j','k','l']
let c=['z','x','c','v','b','n','m'],flag=false,k=[]
for(let i=0;i<words.length;i++){
let n=words[i].toLowerCase().split('')
if(a.includes(n[0])){
for(let j=1;j<n.length;j++){
if(!a.includes(n[j])){
flag=true
break
}
}
}else if(b.includes(n[0])){
for(let j=1;j<n.length;j++){
if(!b.includes(n[j]))
{
flag=true
break
}
}
}else{
for(let j=1;j<n.length;j++){
if(!c.includes(n[j]))
{flag=true
break}
}
}
if(!flag)k.push(words[i])
flag=false
}
return k
};
```
边栏推荐
- Happy sound 2[sing.2]
- Wechat red envelope cover applet source code - background independent version - source code with evaluation points function
- Uni app app half screen continuous code scanning
- 语谱图怎么看
- 功能强大的国产Api管理工具
- Leetcode learning records (starting from the novice village, you can't kill out of the novice Village) ---1
- MariaDB database management system learning (I) installation diagram
- [Yu Yue education] reference materials for surgical skills teaching in Tongji University
- GPS从入门到放弃(十一)、差分GPS
- Huawei has launched attacks in many industries at the same time, and its frightening technology has made European and American enterprises tremble
猜你喜欢

一行代码可以做些什么?

Tiktok will push the independent grass planting app "praiseworthy". Can't bytes forget the little red book?

Make menuconfig has a recipe for target 'menuconfig' failed error

【MySQL】Online DDL详解

Enhance network security of kubernetes with cilium

C how to set two columns comboboxcolumn in DataGridView to bind a secondary linkage effect of cascading events

AI enterprise multi cloud storage architecture practice | Shenzhen potential technology sharing

ViT论文详解

GPS从入门到放弃(十二)、 多普勒定速

The golden age of the U.S. technology industry has ended, and there have been constant lamentations about chip sales and 30000 layoffs
随机推荐
GPS从入门到放弃(十七) 、对流层延时
[asp.net core] set the format of Web API response data -- formatfilter feature
Kohana database
Yyds dry goods inventory C language recursive implementation of Hanoi Tower
Unity3d Learning Notes 6 - GPU instantiation (1)
GPS从入门到放弃(十九)、精密星历(sp3格式)
JPEG2000 matlab source code implementation
The underlying implementation of string
Codeforces Round #274 (Div. 2) –A Expression
GPS从入门到放弃(十三)、接收机自主完好性监测(RAIM)
经纪xx系统节点VIP案例介绍和深入分析异常
Reptile practice (V): climbing watercress top250
小满网络模型&http1-http2 &浏览器缓存
Search element topic (DFS)
Some problems about the use of char[] array assignment through scanf..
Digital transformation takes the lead to resume production and work, and online and offline full integration rebuilds business logic
Guava: use of multiset
GPS from getting started to giving up (16), satellite clock error and satellite ephemeris error
[go][reprint]vscode run a HelloWorld example after configuring go
numpy 下载安装