leetcode第361场周赛补题

7020. 统计对称整数的数目 - 力扣(LeetCode)

思路:转化为字符串后枚举

cpp 复制代码
class Solution {
public:
    int countSymmetricIntegers(int low, int high) {
        int res = 0;
        for(int i = low; i <= high; i ++ )
        {
            string s = to_string(i);
            if(s.size() % 2) continue;
            int pre = 0, suf = 0;
            for(int i = 0; i < s.size() / 2; i ++ ) pre += s[i] - 'a';
            for(int i = s.size() / 2; i < s.size(); i ++ ) suf += s[i] - 'a';
            res += (pre == suf);
        }
        return res;
    }
};

8040. 生成特殊数字的最少操作 - 力扣(LeetCode)

思路:枚举,rfind()

cpp 复制代码
class Solution {
public:
    int minimumOperations(string num) {
        int n = num.size();
        auto f = [&](string tail) {
            int i = num.rfind(tail[1]);
            if(i == string::npos || i == 0) return n;
            i = num.rfind(tail[0], i - 1);
            if(i == string::npos) return n;
            return n - i - 2;
        };
        return min({n - (num.find('0') != string::npos), f("00"), f("25"), f("50"), f("75")});
    }
};
相关推荐
bikong718 分钟前
一种高效绘制余晖波形的方法Qt/C++
数据库·c++·qt
方案开发PCBA抄板芯片解密36 分钟前
什么是算法:高效解决问题的逻辑框架
算法
深耕AI40 分钟前
【MFC文档与视图结构:数据“仓库”与“橱窗”的梦幻联动 + 初始化“黑箱”大揭秘!】
c++·mfc
songx_991 小时前
leetcode9(跳跃游戏)
数据结构·算法·游戏
学c语言的枫子1 小时前
数据结构——双向链表
c语言·数据结构·链表
励志不掉头发的内向程序员1 小时前
STL库——二叉搜索树
开发语言·c++·学习
小白狮ww1 小时前
RStudio 教程:以抑郁量表测评数据分析为例
人工智能·算法·机器学习
AAA修煤气灶刘哥1 小时前
接口又被冲崩了?Sentinel 这 4 种限流算法,帮你守住后端『流量安全阀』
后端·算法·spring cloud
tan180°2 小时前
Boost搜索引擎 查找并去重(3)
linux·c++·后端·搜索引擎
Boop_wu2 小时前
[数据结构] 栈 · Stack
数据结构