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

g1001_1100.s1018_binary_prefix_divisible_by_5.Solution Maven / Gradle / Ivy

There is a newer version: 1.37
Show newest version
package g1001_1100.s1018_binary_prefix_divisible_by_5;

// #Easy #Array #2022_02_25_Time_3_ms_(84.58%)_Space_49.7_MB_(32.50%)

import java.util.ArrayList;
import java.util.List;

public class Solution {
    public List prefixesDivBy5(int[] a) {
        List result = new ArrayList<>(a.length);
        int remainder = 0;
        for (int j : a) {
            remainder = (j + (remainder << 1)) % 5;
            result.add(remainder == 0);
        }
        return result;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy