• + 0 comments

    java

    Map<String, Integer> m = new HashMap<String, Integer>();
    for (int i = 0; i < stringList.size(); i++) {
    		String val = stringList.get(i);
    		if (m.containsKey(val)) {
    				m.put(val, m.get(val) + 1);
    		} else {
    				m.put(val, 1);
    		}
    }
    
    List<Integer> res = new ArrayList<Integer>(queries.size());
    for (int j = 0; j < queries.size(); j++) {
    		Integer newVal = m.getOrDefault(queries.get(j), 0);
    		res.add(newVal);
    }
            
            return res;