天天看點

建信金融科技--軟開筆試題1.答案--java--9.12

package jiansheBank;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class Jianxin_2 {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String s1=br.readLine();
		s1=s1.substring(1,s1.length()-1);
		String s2=br.readLine();
		s2=s2.substring(1,s2.length()-1);
		String[] strs=uncommonFromSentences(s1, s2);
		System.out.println(Arrays.toString(strs));
	}
	
	    public static String[] uncommonFromSentences(String A, String B) {
	        Map<String, Integer> count = new HashMap<>();
	        for (String word: A.split(" "))
	            count.put(word, count.getOrDefault(word, 0) + 1);
	        for (String word: B.split(" "))
	            count.put(word, count.getOrDefault(word, 0) + 1);

	        List<String> ans = new LinkedList<>();
	        for (String word: count.keySet()) {
	        	if (count.get(word) == 1) {
	        		word="""+word+""";
	                ans.add(word);
	        	}
	            	
	        }
	            

	        return ans.toArray(new String[ans.size()]);
	    
	}

}
//"this apple is sweet"
//"this apple is sour"
           

和力扣884一樣