【LeetCode】500. Keyboard Row
来源:互联网 发布:淘宝美工和室内设计师 编辑:程序博客网 时间:2024/06/05 09:35
Given a List of words, return the words that can be typed using letters of alphabet on only one row's of American keyboard like the image below.
Example 1:
Input: ["Hello", "Alaska", "Dad", "Peace"]Output: ["Alaska", "Dad"]
Note:
- You may use one character in the keyboard more than once.
- You may assume the input string will only contain letters of alphabet.
很简单的一个题目,判断给定单词是不是能在键盘上用一行打出来。
var s1='qwertyuiopQWERTYUIOP',s2='asdfghjklASDFGHJKL',s3='zxxcvbnmZXCVBNM';var findWords = function(words) { var ret=[]; for(var i=0;i<words.length;i++){ var flag=true; if(s1.indexOf(words[i][0])>=0){ for(var j=0;j<words[i].length;j++){ if(s1.indexOf(words[i][j])<0){ flag=false; } } }else if(s2.indexOf(words[i][0])>=0){ for(var j=0;j<words[i].length;j++){ if(s2.indexOf(words[i][j])<0){ flag=false; } } }else if(s3.indexOf(words[i][0])>=0){ for(var j=0;j<words[i].length;j++){ if(s3.indexOf(words[i][j])<0){ flag=false; } } } if(flag){ ret.push(words[i]); } } return ret;};
阅读全文
0 0
- Leetcode-500. Keyboard Row
- 【Leetcode】500. Keyboard Row
- 【LeetCode】500. Keyboard Row
- LeetCode 500. Keyboard Row
- LeetCode 500. Keyboard Row
- leetcode 500. Keyboard Row
- [LeetCode]500. Keyboard Row
- LeetCode | 500. Keyboard Row
- [LeetCode]500. Keyboard Row
- LeetCode 500. Keyboard Row
- 【LeetCode】500. Keyboard Row
- Leetcode 500. Keyboard Row
- LeetCode 500. Keyboard Row
- LeetCode 500. Keyboard Row
- [leetcode]: 500. Keyboard Row
- leetcode 500. Keyboard Row
- [leetcode] 500. Keyboard Row
- LeetCode 500. Keyboard Row
- centos7下的FastDFS5.09的安装与使用
- 每日AC-leetcode word-break-ii -与dubbo 异步回调问题
- 佳能图像处理软件(Canon Utilities ZoomBrowser EX)下载 v62.0官方版
- HDU 5361(最短路+并查集优化)
- 导入一个AndroidStudio工程作为一个Library Module
- 【LeetCode】500. Keyboard Row
- 洛谷 P3369 【模板】普通平衡树(Treap/SBT)
- Win10 系统时间错误
- Spring AOP实例
- 分配并注册主次设备号
- Maven Tomcat8+ 实现自动化部署
- python爬虫利器-request库
- java.io.Serializable浅析
- 快速入门shell脚本编写(四)