1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| class Solution { public int[] divisibilityArray(String word, int m) { int[] res = new int[word.length()]; long tmp = 0;
for (int j = 0; j < word.length(); j++) { tmp = tmp * 10 + (word.charAt(j) - '0'); long extra = tmp % m; if (extra == 0) { res[j] = 1; } tmp = extra; }
return res; } }
|
References
2575. Find the Divisibility Array of a String