2021-09-17每日刷题打卡

一、POJ-1112:Team Them Up!

1.1 问题描述

Your task is to divide a number of persons into two teams, in such a way, that:

everyone belongs to one of the teams;

every team has at least one member;

every person in the team knows every other person in his team;

teams are as close in their sizes as possible.

This task may have many solutions. You are to find and output any solution, or to report that the solution does not exist.

题目大意:

将一群人按照如下规则分成两个队:

(1)一个人属于其中一个队

(2)每支队伍至少一名成员

(3)每支队伍的队员之间都相互认识,不同队伍就不认识了

(4)队伍的规模尽可能相近

找出其中一种这样的组织方法,如果没有就说一下不存在

1.2 问题解决

没看懂题解

二、Leetcode-387:字符串中的第一个唯一字符

2.1 问题描述

img

2.2 问题分析

比较简单的哈希表问题,但是检查出自身对哈西表的常用方法不熟悉。

2.3 问题解决

class Solution {
    public int firstUniqChar(String s) {
        Map<Character, Integer> map = new HashMap<>();

        for(int i = 0; i < s.length(); i++)
            map.put(s.charAt(i), map.getOrDefault(s.charAt(i), 0) + 1);
        
        for(int i = 0; i < s.length(); i++)
            if(map.get(s.charAt(i)) == 1)
                return i;

        return -1;        
    }
}

三、生词

as … as possible 尽可能 ---- as close in their sizes as possible 规模上尽可能接近

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值