Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mport java.util.*; class Solution { private static final List DICTIONARY = Arrays.asList("i", "a", "am", "uber"); public static boolean isSentence(final String sentence) { // Modify here String out = sentence; for(String word : DICTIONARY) { out = out.replaceAll(word, ""); } return out.isEmpty(); } public static void main(String[] args) { checkSentence("iamuber"); // true checkSentence("amiuberiam"); // true checkSentence("ixam"); // false } public static void checkSentence(String example) { Collections.sort(DICTIONARY, new Comparator() { public int compare(String o1, String o2) { return o1.length() > o2.length(); } }); System.out.println(example + " --> " + isSentence(example)); } }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement