package leetcode;

/**
 * https://leetcode.com/problems/keyboard-row/
 */
public class Problem500 {
    public String[] findWords(String[] words) {
        // TODO
        return new String[]{};
    }

    public static void main(String[] args) {
        Problem500 prob = new Problem500();
        System.out.println(prob.findWords(new String[]{"Hello", "Alaska", "Dad", "Peace"})); // ["Alaska", "Dad"]
    }
}

@@ -12,16 +12,116 @@
 tcode;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.HashMap;%0Aimport java.util.List;%0Aimport java.util.Map;%0A%0A
 /**%0A * h
@@ -253,256 +253,1018 @@
     
-// TODO%0A        return new String%5B%5D%7B%7D
+List%3CString%3E result = new ArrayList%3C%3E();%0A        Map%3CCharacter, Integer%3E map = new HashMap%3C%3E();%0A        update(map, %22qwertyuiop%22, 1)
 ;%0A    
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem500 prob = new Problem500();%0A        System.out.println(prob.findWords(new String%5B%5D%7B%22Hello%22, %22Alaska%22, %22Dad%22, %22Peace%22%7D)); // %5B%22Alaska%22, %22Dad%22%5D
+update(map, %22asdfghjkl%22, 2);%0A        update(map, %22zxcvbnm%22, 3);%0A        for (int i = 0; i %3C words.length; i++) %7B%0A            String word = words%5Bi%5D.toLowerCase();%0A            int row = 0;%0A            boolean valid = true;%0A            for (int j = 0; j %3C word.length(); j++) %7B%0A                if (j == 0) %7B%0A                    row = map.get(word.charAt(j));%0A                %7D else %7B%0A                    if (row != map.get(word.charAt(j))) %7B%0A                        valid = false;%0A                        break;%0A                    %7D%0A                %7D%0A            %7D%0A            if (valid) %7B%0A                result.add(words%5Bi%5D);%0A            %7D%0A        %7D%0A        return result.toArray(new String%5B0%5D);%0A    %7D%0A%0A    private static void update(Map%3CCharacter, Integer%3E map, String str, int row) %7B%0A        for (char c : str.toCharArray()) %7B%0A            map.put(c, row);%0A        %7D
 %0A   

Solve problem 500