By Java 8 Lambdas/Stream APIs


  • 0
    X

    Refer to : java API docs and Java 8

    s.chars().collect(HashMap::new, (m, e) -> m.compute(e, (k, v) -> v == null ? 1 : null), (m1, m2) -> m1.putAll(m2)).size() <= 1
    
    // Or: CharStream.from(s).collect(HashMap::new, (m, e) -> m.compute(e, (k, v) -> v == null ? 1 : null)).size() <= 1;
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.