您的位置:首页 > 财经 > 产业 > app设计工具_好用建站模板_免费制作链接_刚刚刚刚刚刚好痛

app设计工具_好用建站模板_免费制作链接_刚刚刚刚刚刚好痛

2025/7/14 18:40:40 来源:https://blog.csdn.net/mobius_strip/article/details/143996419  浏览:    关键词:app设计工具_好用建站模板_免费制作链接_刚刚刚刚刚刚好痛
app设计工具_好用建站模板_免费制作链接_刚刚刚刚刚刚好痛

Problem

Given an array of strings words, return the words that can be typed using letters of the alphabet on only one row of American keyboard like the image below.

Note that the strings are case-insensitive, both lowercased and uppercased of the same letter are treated as if they are at the same row.

In the American keyboard:

  • the first row consists of the characters “qwertyuiop”,
  • the second row consists of the characters “asdfghjkl”, and
  • the third row consists of the characters “zxcvbnm”.

在这里插入图片描述

Algorithm

The simplest algorithm is to directly compare using enumeration, or you can use a dictionary to store queries.

Code

class Solution:def findWords(self, words: List[str]) -> List[str]:row = ["qwertyuiop", "asdfghjkl", "zxcvbnm"]ans = []for word in words:find_letter = [0, 0, 0]for letter in word:if letter >= 'A' and letter <= 'Z':letter = chr(ord(letter) + ord('a') - ord('A'))for i in range(3):for s in row[i]:if s == letter:find_letter[i] = 1breakif find_letter[0] + find_letter[1] + find_letter[2] == 1:ans.append(word)return ans

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com