leetcode2154. 将找到的值乘以 2【278场周赛】(java)

简单题重拳出击

class Solution {
    public int findFinalValue(int[] nums, int original) {
        int n = nums.length;
        Arrays.sort(nums);
        int id = original;
        int count = 0;
        for(int i = 0; i < n; i ++){
            if(nums[i] == id){
                nums[i] *= 2;
                id *= 2;
                count ++;
            }
        }
        if(count >= 1){
            return id;
        }else{
            return original;
        }

    }
}

你可能感兴趣的:(学习做题leetcode,java,leetcode,周赛,排序)