题解 | 小欧的奇数

import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine());
        String s = scanner.nextLine();

        int ji = 0,ou = 0;
        for(String s_num:s.split(" ")){
            int num = Integer.parseInt(s_num);
            if (num%2==0) ou+=1;
            else ji+=1;
        }
        if(ji+ou<3){
            System.out.println("NO");
        }else{
            if ((ji>=1 && ou>=2) || (ji>=3)) System.out.println("YES");
            else System.out.println("NO");
        }
    }
}

3个数和为偶的唯二情况:①3个奇、②2偶+1奇、据此做出if判断即可

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务