All Downloads are FREE. Search and download functionalities are using the official Maven repository.

g3201_3300.s3295_report_spam_message.Solution Maven / Gradle / Ivy

The newest version!
package g3201_3300.s3295_report_spam_message;

// #Medium #Array #String #Hash_Table #2024_09_24_Time_39_ms_(98.87%)_Space_85.4_MB_(9.13%)

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class Solution {
    public boolean reportSpam(String[] message, String[] bannedWords) {
        Set bannedUnique = new HashSet<>(Arrays.asList(bannedWords));
        int bannedCount = 0;
        for (String msg : message) {
            if (bannedUnique.contains(msg)) {
                bannedCount++;
            }
            if (bannedCount == 2) {
                return true;
            }
        }
        return false;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy