二刷 08/2022
Version #1 Math
好像也可以用gce做
Time O(q)?
Space O(1)
Runtime: 0 ms, faster than 100.00% of Java online submissions for Mirror Reflection.
Memory Usage: 41.8 MB, less than 8.33% of Java online submissions for Mirror Reflection.
class Solution {
public int mirrorReflection(int p, int q) {
int h = 1, w = 1;
while (h * p != w * q) {
w++;
h = w * q / p;
}
if (w % 2 == 1) {
if (h % 2 == 1) {
return 1;
}
return 0;
}
return 2;
}
}
一刷
根本不会
Ref
https://buptwc.github.io/2018/06/26/Leetcode-858-Mirror-Reflection/
https://blog.csdn.net/fuxuemingzhu/article/details/82432579
100.00 %
class Solution {
public int mirrorReflection(int p, int q) {
// k * p = r * q
int k = 1;
while (k * p % q != 0) {
k++;
}
int r = k * p / q;
if (k % 2 == 0) {
return 0;
} else if (r % 2 == 0) {
return 2;
} else {
return 1;
}
}
}
No comments:
Post a Comment