随笔分类 -  leetcode

摘要:5621. 无法吃午餐的学生数量 思维 判断栈中那种三明治比所需人多,找多出来的位置以后便是不可取的 class Solution { public: int countStudents(vector<int>& students, vector<int>& sandwiches) { int n 阅读全文
posted @ 2020-12-26 23:56 DWVictor 阅读(110) 评论(1) 推荐(0)
摘要:5629. 重新格式化电话号码 模拟 注意一些细节,最后位置是否取值。 class Solution { public: string reformatNumber(string number) { string s; for (auto c: number) if (c != ' ' && c ! 阅读全文
posted @ 2020-12-20 13:02 DWVictor 阅读(157) 评论(0) 推荐(0)
摘要:1684. 统计一致字符串的数目 简单模拟 class Solution { public: int countConsistentStrings(string allowed, vector<string>& words) { int n = words.size(),num = 0; int h 阅读全文
posted @ 2020-12-18 16:31 DWVictor 阅读(100) 评论(0) 推荐(0)
摘要:1688. 比赛中的配对次数 共有n个队伍,一个冠军,需要淘汰n-1个 队伍。 每一场比赛淘汰一个队伍,因此进行了n-1场比赛。 所以共有n-1个配对。 class Solution { public: int numberOfMatches(int n) { return n - 1; } }; 阅读全文
posted @ 2020-12-17 13:41 DWVictor 阅读(121) 评论(0) 推荐(0)
摘要:让我们从一个题目入手 从一个大小为n的整数集中选取一些元素,使得它们的和等于给定的值T。每个元素限选一次,不能一个都不选。 关于这个题目,我们很容易想到的便是对所有元素进行暴力搜索,然后进行剪枝便可。 下面我将介绍二进制枚举的思路和流程来巧妙的解决这个问题。 对任一数来说,所面临的问题是取或不取,在 阅读全文
posted @ 2020-12-07 21:53 DWVictor 阅读(434) 评论(0) 推荐(0)
摘要:5617. 设计 Goal 解析器 按题意模拟,基础题。 class Solution { public: string str; string interpret(string command) { for(int i = 0; i < command.size();i++){ if(comman 阅读全文
posted @ 2020-12-07 21:21 DWVictor 阅读(118) 评论(0) 推荐(0)