题解 | #数组分组#

数组分组

http://www.nowcoder.com/practice/9af744a3517440508dbeb297020aca86

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = Integer.valueOf(scan.nextLine().trim());
        String[] strs = scan.nextLine().split(" ");
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = Integer.valueOf(strs[i].trim());
        }
        int multiple3 = 0;
        int multiple5 = 0;
        System.out.println(process(multiple3, multiple5, nums, 0));
    }
    public static boolean process(int multiple3, int multiple5, int[] nums, int index) {
        if (index == nums.length) {
            if (multiple3 == multiple5) {
                return true;
            } else {
                return false;
            }
        }
        int currentNum = nums[index];
        if (currentNum % 5 == 0) {
            if (process(multiple3, multiple5 + currentNum, nums, index + 1)) {
                return true;
            } else {
                return false;
            }
        } else if (currentNum % 3 == 0) {
            if (process(multiple3 + currentNum, multiple5, nums, index + 1)) {
                return true;
            } else {
                return false;
            }
        } else {
            if (process(multiple3, multiple5 + currentNum, nums, index + 1)) {
                return true;
            }
            if (process(multiple3 + currentNum, multiple5, nums, index + 1)) {
                return true;
            }
            return false;
        }
    }
}
全部评论
该牛油正在参与牛客写题解薅羊毛的活动,牛币,周边,京东卡超多奖品放送,活动进入倒计时!快来捡漏啦https://www.nowcoder.com/discuss/888949?source_id=profile_create_nctrack&channel=-1
点赞 回复 分享
发布于 2022-04-27 11:43

相关推荐

06-17 00:26
门头沟学院 Java
程序员小白条:建议换下项目,智能 AI 旅游推荐平台:https://github.com/luoye6/vue3_tourism_frontend 智能 AI 校园二手交易平台:https://github.com/luoye6/vue3_trade_frontend GPT 智能图书馆:https://github.com/luoye6/Vue_BookManageSystem 选项目要选自己能掌握的,然后最好能自己拓展的,分布式这种尽量别去写,不然你只能背八股文了,另外实习的话要多投,尤其是学历不利的情况下,多找几段实习,最好公司title大一点的
无实习如何秋招上岸
点赞 评论 收藏
分享
程序员牛肉:主要是因为小厂的资金本来就很吃紧,所以更喜欢有实习经历的同学。来了就能上手。 而大厂因为钱多,实习生一天三四百的就不算事。所以愿意培养你,在面试的时候也就不在乎你有没有实习(除非是同级别大厂的实习。) 按照你的简历来看,同质化太严重了。项目也很烂大街。 要么换项目,要么考研。 你现在选择工作的话,前景不是很好了。
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
昨天 15:39
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务