Version #1 DP
37.50 %
class Solution {
public int countTriplets(int[] A) {
int N = 1 << 16;
int[] dp = new int[N];
for (int a : A) {
dp[a] += 1;
}
for (int i = 0; i < 2; i++) {
int[] temp = new int[N];
for (int k = 0; k < N; k++) {
for (int a : A) {
temp[k & a] += dp[k];
}
}
dp = temp;
}
return dp[0];
}
}
No comments:
Post a Comment