100131. 使三个字符串相等
⭐ AC code
class Solution {public int findMinimumOperations(String s1, String s2, String s3) {int len1 = s1.length();int len2 = s2.length();int len3 = s3.length();int n = Math.min(len1,len2);n = Math.min(n,len3);int i = 0;while(i < n){if(s1.charAt(i) != s2.charAt(i) || s2.charAt(i) != s3.charAt(i))break;i++;}if(i == 0)return -1;return len1 + len2 + len3 - i * 3;}
}
100122. 区分黑球与白球
求 0 左边 1 的个数(交换两个 0 是没有意义的)
⭐ AC code
class Solution {public long minimumSteps(String s) {long ans = 0;long cnt = 0;for(int i = 0; i < s.length(); i++){char c = s.charAt(i);if(c == '0')ans += cnt;elsecnt++;}return ans;}
}
100119. 最大异或乘积
⭐ AC code
import java.math.BigDecimal;
class Solution {public int maximumXorProduct(long a, long b, int n) {int mod = (int) (1e9 + 7);BigDecimal pre = BigDecimal.valueOf(a).multiply(BigDecimal.valueOf(b));for (int i = n - 1; i >= 0; i--) {long a1 = a ^ (1L << i);long b1 = b ^ (1L << i);BigDecimal cur = BigDecimal.valueOf(a1).multiply(BigDecimal.valueOf(b1));if (cur.subtract(pre).doubleValue() > 0) {a = a1;b = b1;pre = cur;}}long a1 = (a) % mod;long b1 = (b) % mod;return (int) (a1 * b1 % mod);}
}
👨🏫 大佬题解