package com.fishercoder.solutions;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 884. Uncommon Words from Two Sentences
 *
 * We are given two sentences A and B.  (A sentence is a string of space separated words.  Each word consists only of lowercase letters.)
 *
 * A word is uncommon if it appears exactly once in one of the sentences, and does not appear in the other sentence.
 *
 * Return a list of all uncommon words.
 *
 * You may return the list in any order.
 *
 *
 *
 * Example 1:
 *
 * Input: A = "this apple is sweet", B = "this apple is sour"
 * Output: ["sweet","sour"]
 * Example 2:
 *
 * Input: A = "apple apple", B = "banana"
 * Output: ["banana"]
 *
 *
 * Note:
 *
 * 0 <= A.length <= 200
 * 0 <= B.length <= 200
 * A and B both contain only spaces and lowercase letters.
 */
public class _884 {
  public static class Solution1 {
    public String[] uncommonFromSentences(String A, String B) {
      Map<String, Integer> map = new HashMap<>();
      for (String word : A.split(" ")) {
        map.put(word, map.getOrDefault(word, 0) + 1);
      }

      for (String word : B.split(" ")) {
        map.put(word, map.getOrDefault(word, 0) + 1);
      }
      List<String> result = new ArrayList<>();
      for (String key : map.keySet()) {
        if (map.get(key) == 1) {
          result.add(key);
        }
      }
      String[] strs = new String[result.size()];
      result.toArray(strs);
      return strs;
    }
  }
}

@@ -133,728 +133,8 @@
 p;%0A%0A
-/**%0A * 884. Uncommon Words from Two Sentences%0A *%0A * We are given two sentences A and B.  (A sentence is a string of space separated words.  Each word consists only of lowercase letters.)%0A *%0A * A word is uncommon if it appears exactly once in one of the sentences, and does not appear in the other sentence.%0A *%0A * Return a list of all uncommon words.%0A *%0A * You may return the list in any order.%0A *%0A *%0A *%0A * Example 1:%0A *%0A * Input: A = %22this apple is sweet%22, B = %22this apple is sour%22%0A * Output: %5B%22sweet%22,%22sour%22%5D%0A * Example 2:%0A *%0A * Input: A = %22apple apple%22, B = %22banana%22%0A * Output: %5B%22banana%22%5D%0A *%0A *%0A * Note:%0A *%0A * 0 %3C= A.length %3C= 200%0A * 0 %3C= B.length %3C= 200%0A * A and B both contain only spaces and lowercase letters.%0A */%0A
 publ
@@ -149,16 +149,18 @@
  _884 %7B%0A
+  
   public
@@ -185,16 +185,20 @@
 tion1 %7B%0A
+    
     publ
@@ -249,24 +249,30 @@
 String B) %7B%0A
+      
       Map%3CSt
@@ -307,32 +307,38 @@
 hMap%3C%3E();%0A      
+   
+   
 for (String word
@@ -348,32 +348,40 @@
 A.split(%22 %22)) %7B%0A
+        
         map.put(
@@ -428,11 +428,23 @@
     
+   
-%7D%0A%0A
+   %7D%0A%0A      
     
@@ -480,32 +480,40 @@
 %22 %22)) %7B%0A        
+    
+    
 map.put(word, ma
@@ -548,24 +548,36 @@
 ;%0A      
-%7D%0A
+      %7D%0A   
       
+   
 List%3CStr
@@ -605,24 +605,30 @@
 ayList%3C%3E();%0A
+      
       for (S
@@ -663,16 +663,24 @@
         
+    
+    
 if (map.
@@ -702,24 +702,34 @@
 %7B%0A          
+         
+ 
 result.add(k
@@ -741,24 +741,46 @@
         
+        %7D%0A            
 %7D%0A      
 %7D%0A      
@@ -767,26 +767,24 @@
     %7D%0A      
-%7D%0A
       String
@@ -822,24 +822,30 @@
 e()%5D;%0A      
+     
+ 
 result.toArr
@@ -854,16 +854,22 @@
 (strs);%0A
+      
       re
@@ -883,16 +883,22 @@
 rs;%0A    
-%7D%0A
+    %7D%0A  
   %7D%0A%7D%0A

refactor 884