LeetCode-500-Keyboard Row
来源:互联网 发布:广州哪里有淘宝美工学 编辑:程序博客网 时间:2024/05/22 11:47
https://leetcode.com/problems/keyboard-row/description/
#region Keyboard Row //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. public string[] FindWords(string[] words) { HashSet<string> hash_line1 = new HashSet<string>() { "q", "w", "e", "r", "t", "y", "u", "i", "o", "p" }; HashSet<string> hash_line2 = new HashSet<string>() { "a", "s", "d", "f", "g", "h", "j", "k", "l" }; HashSet<string> hash_line3 = new HashSet<string>() { "z", "x", "c", "v", "b", "n", "m" }; List<string> list = new List<string>(); for (int i = 0; i < words.Length; i++) { if (IsInHashSet(hash_line1, words[i]) || IsInHashSet(hash_line2, words[i]) || IsInHashSet(hash_line3, words[i])) { list.Add(words[i]); } } return list.ToArray(); } bool IsInHashSet(HashSet<string> hash, string strWord) { for (int i = 0; i < strWord.Length; i++) { if (!hash.Contains(strWord[i].ToString().ToLower())) return false; } return true; } #endregion
阅读全文
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 C++
- leetcode 500 Keyboard Row Add to List
- Leetcode-500. Keyboard Row
- 【Leetcode】500. Keyboard Row
- 【LeetCode】500. Keyboard Row
- LeetCode 500. Keyboard Row
- LeetCode 500. Keyboard Row
- [ACM]CCF CSP [201609-5]E题 祭坛
- 讨论构造拷贝构造的N中调用情况的问题
- 秒杀多线程第五篇 经典线程同步 关键段CRITICAL_SECTION
- HBase vs. MongoDB vs. MySQL vs. Oracle vs. Redis,三大主流开源 NoSQL 数据库的 PK 两大主流传统 SQL 数据库
- C++ string assign()用法
- LeetCode-500-Keyboard Row
- hadoop-2.4 伪分布式环境搭建
- 从ELK到EFK,日志系统的高级玩法儿
- gulp与webpack的区别
- pyQt5-控件1
- Linux-make命令相关
- android 圆角图片实现(三)
- 使用fseek()函数从文件尾部前移并且写入数据
- java 通过user-agent获取客户端