[LeetCode]#500. Keyboard Row

  • 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".
Input: words = ["Hello","Alaska","Dad","Peace"]
Output: ["Alaska","Dad"]
  1. There are three set{} which are {‘p’, ‘i’, ‘o’, ‘u’, ‘q’, ‘w’, ‘t’, ‘y’, ‘e’, ‘r’}, {‘s’, ‘f’, ‘j’, ‘d’, ‘k’, ‘l’, ‘g’, ‘h’, ‘a’}, {‘m’, ‘b’, ‘c’, ‘v’, ‘x’, ’n’, ‘z’}
  2. If input set is subset of step1 set. Append it to ans[]
  3. Return ans.
class Solution:
def findWords(self, words):
ans=[]
set1=set("qwertyuiop")
set2=set("asdfghjkl")
set3=set("zxcvbnm")
for i in words:
if set(i.lower()) <= set1:
ans.append(i)
elif set(i.lower()) <= set2:
ans.append(i)
elif set(i.lower()) <= set3:
ans.append(i)
return ans

--

--

--

Interesting in any computer science.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Sunlight is the Best Disinfectant: The Value of Code “Fingerprints”

Journey into the IO Monad (Part 2)

Why “Agile” is complete and utter bollocks. (Part 3)

Serverless Puppeteer — Use Cases in 2022

The Biggest Takeaway From My First Year as a Software Developer

Card that says “What can you do today that you couldn’t do a year ago?”

How to Create Database Backup in Laravel

How to Create Database Backup in Laravel

Benchmarking read/write speed on Amazon Aurora, classic RDS and local disk

CS373 Fall 2020: Week 4

The most beautiful human to grace the earth

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Fatboy Slim

Fatboy Slim

Interesting in any computer science.

More from Medium

Python Interview Questions for 2022

[LeetCode]#2114. Maximum Number of Words Found in Sentences

Introduction to Automated Testing with Python

Binary Search