sweet1cris

Untitled

Feb 9th, 2018
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.83 KB | None | 0 0
  1.  
  2. public class Solution {
  3.     /*
  4.      * @param : a given string
  5.      * @param : another given string
  6.      * @return: An array of missing string
  7.      */
  8.     public List<String> missingString(String str1, String str2) {
  9.         // Write your code here
  10.         List<String> res = new ArrayList<>();
  11.         if (str1.length() > str2.length()) {
  12.             String temp = str1;
  13.             str1 = str2;
  14.             str2 = temp;
  15.         }
  16.        
  17.         String[] arr1 = str1.split(" ");
  18.         String[] arr2 = str2.split(" ");
  19.         Set<String> set = new HashSet<>();
  20.        
  21.         for (String str : arr1) {
  22.             set.add(str);
  23.         }
  24.        
  25.         for (String str : arr2) {
  26.             if (!set.contains(str)) {
  27.                 res.add(str);
  28.             }
  29.         }
  30.        
  31.         return res;
  32.     }
  33. };
Advertisement
Add Comment
Please, Sign In to add comment