網(wǎng)站建設(shè)介紹seo網(wǎng)絡(luò)營(yíng)銷外包
題目
教學(xué)過(guò)程中,教練示范一次,學(xué)員跟做三次。該過(guò)程被混亂剪輯后,記錄于數(shù)組 actions,其中 actions[i] 表示做出該動(dòng)作的人員編號(hào)。請(qǐng)返回教練的編號(hào)。
示例 1:
輸入:actions = [5, 7, 5, 5]
輸出:7
示例 2:
輸入:actions = [12, 1, 6, 12, 6, 12, 6]
輸出:1
提示:
1 <= actions.length <= 10000
1 <= actions[i] < 2^31
代碼
class Solution {
public int trainingPlan(int[] nums) {
int[] res = new int[32];
int m = 1;
int sum = 0;
for(int i = 0; i < 32; i++){
for(int j = 0; j < nums.length; j++){
if((nums[j] & m) != 0){
res[i]++;
}
}
res[i] = res[i] % 3;sum = sum + res[i] * m;m = m << 1;}return sum;
}
}