Leetcode in Java && Oracle
421 subscribers
8 photos
397 files
400 links
Second channel: @codeforces_java

Let's Develop Together!
Download Telegram
image_2021-12-06_11-27-57.png
77.3 KB
#N500. Keyboard Row
problem link

#solution
class Solution {
public String[] findWords(String[] words) {
String row1="QWERTYUIOPqwertyuiop";
String row2="ASDFGHJKLasdfghjkl";
String row3="ZXCVBNMzxcvbnm";
List<String> list = new ArrayList<>();
for(String word:words){
int[][] counter = new int[1][3];
for(int i=0; i<word.length(); i++){
if(row1.contains(word.valueOf(word.charAt(i))))
counter[0][0]++;
if(row2.contains(word.valueOf(word.charAt(i))))
counter[0][1]++;
if(row3.contains(word.valueOf(word.charAt(i))))
counter[0][2]++;
}
if(counter[0][0]==word.length()||counter[0][1]==word.length()||counter[0][2]==word.length()) list.add(word);
}
return list.toArray(new String[0]);
}
}