LC.P2437[有效时间的数目] 方法一:乘法原理12345678910111213141516class Solution { public int countTime(String time) { return count(time.substring(0, 2), 24) * count(time.substring(3, 5), 60); } private int count(String time, int x) { int ans = 0; char[] s = time.toCharArray(); for (int i = 0; i < x; ++i) { if ((s[0] == '?' || i / 10 == s[0] - '0') && (s[1] == '?' || i % 10 == s[1] - '0')) { ++ans; } } return ans; }} 时间复杂度:$O(24 + 60) = O(1)$ 空间复杂度:$O(1)$