1 Star 0 Fork 0

孙启萌 / leetcode

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
500.键盘行.js 1005 Bytes
一键复制 编辑 原始数据 按行查看 历史
孙启萌 提交于 2023-05-16 15:15 . 刷题
/*
* @lc app=leetcode.cn id=500 lang=javascript
*
* [500] 键盘行
*/
// @lc code=start
/**
* @param {string[]} words
* @return {string[]}
*/
var findWords = function(words) {
let arr = ['qwertyuiop', 'asdfghjkl', 'zxcvbnm']
let result = []
for (let index1 = 0; index1 < words.length; index1++) {
const str = words[index1];
const lowerStr = str.toLocaleLowerCase()
let first = -1
if (arr[0].includes(lowerStr[0])) {
first = 0
} else if (arr[1].includes(lowerStr[0])) {
first = 1
} else if (arr[2].includes(lowerStr[0])) {
first = 2
}
let flag = true
for (let index2 = 1; index2 < lowerStr.length; index2++) {
const char = lowerStr[index2];
if (!arr[first].includes(char)) {
flag = false
break
}
}
if (flag) {
result.push(str)
}
}
return result
};
// @lc code=end
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sqm147896325/leetcode.git
git@gitee.com:sqm147896325/leetcode.git
sqm147896325
leetcode
leetcode
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891