20210418第 237 场周赛(一)

5734. 判断句子是否为全字母句

全字母句 指包含英语字母表中每个字母至少一次的句子。

给你一个仅由小写英文字母组成的字符串 sentence ,请你判断 sentence 是否为 全字母句 。

如果是,返回 true ;否则,返回 false 。

来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/check-if-the-sentence-is-pangram


class Solution:
    def checkIfPangram(self, sentence: str) -> bool:
        return len(set(list(sentence)))==26

 

5735. 雪糕的最大数量

夏日炎炎,小男孩 Tony 想买一些雪糕消消暑。

商店中新到 n 支雪糕,用长度为 n 的数组 costs 表示雪糕的定价,其中 costs[i] 表示第 i 支雪糕的现金价格。Tony 一共有 coins 现金可以用于消费,他想要买尽可能多的雪糕。

给你价格数组 costs 和现金量 coins ,请你计算并返回 Tony 用 coins 现金能够买到的雪糕的 最大数量 。

注意:Tony 可以按任意顺序购买雪糕。

 1 class Solution {
 2 public:
 3     int maxIceCream(vector<int>& a, int coins) {
 4        sort(a.begin(),a.end());
 5        int res = 0;
 6        for(auto x : a)
 7        {
 8            if(coins >= x)
 9            {
10                coins -= x;
11                res += 1;
12            }
13        }
14     return res;
15     }
16 };

1835. 所有数对按位与结果的异或和

列表的 异或和(XOR sum)指对所有元素进行按位 XOR 运算的结果。如果列表中仅有一个元素,那么其 异或和 就等于该元素。

    例如,[1,2,3,4] 的 异或和 等于 1 XOR 2 XOR 3 XOR 4 = 4 ,而 [3] 的 异或和 等于 3 。

给你两个下标 从 0 开始 计数的数组 arr1 和 arr2 ,两数组均由非负整数组成。

根据每个 (i, j) 数对,构造一个由 arr1[i] AND arr2[j](按位 AND 运算)结果组成的列表。其中 0 <= i < arr1.length 且 0 <= j < arr2.length 。

返回上述列表的 异或和 。

 1 class Solution {
 2 public:
 3     int getXORSum(vector<int>& a, vector<int>& b) {
 4     int n = a.size();
 5     int res = 0;
 6     for(int k =30 ; k>=0 ; --k)
 7     {
 8         int x=0,y=0;
 9         for(auto& e : a) x += e >> k & 1;
10         for(auto& e : b) y += e >> k & 1;
11         if((x & 1)&& (y & 1)) res |= 1 << k;
12     }
13     return ans;
14     }
15 };

 

参考链接:https://leetcode-cn.com/problems/find-xor-sum-of-all-pairs-bitwise-and/

 

posted @ 2021-04-18 11:38  白雪儿  Views(55)  Comments(0Edit  收藏  举报