GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — leetcode/src/BinaryPrefixDivisibleBy5.java at master · LeBW/leetcode Expand file tree/ Copy pathBinaryPrefixDivisibleBy5.javaMore file actions 24 lines (23 loc) · 718 Bytes / Copy pathBinaryPrefixDivisibleBy5.javaFile metadata and controls24 lines (23 loc) · 718 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 import java.util.ArrayList; import java.util.List; /** * 1018. Binary Prefix Divisible by 5 * 考虑到数组A可能很长,直接计算的话值可能会很大甚至溢出,因此每次计算的时候我们只考虑余数就好。 * @author LBW */ public class BinaryPrefixDivisibleBy5 { public List<Boolean> prefixesDivBy5(int[] A) { List<Boolean> ans = new ArrayList<>(); int cur = 0; for (int i: A) { cur = (cur * 2 + i) % 5; // 这里计算的时候直接取余,可以有效防止溢出 if (cur == 0) { ans.add(true); } else { ans.add(false); } } return ans; } } |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |