技术栈

1399. 统计最大组的数目

咔咔咔的2025-05-02 3:07

1399. 统计最大组的数目


题目链接:1399. 统计最大组的数目

代码如下:

cpp 复制代码
class Solution {
public:
	int countLargestGroup(int n) {
		int res = 0;
		unordered_map<int, int> um;
		int maxValue = 0;
		for (int i = 1;i <= n;i++) {
			string value =to_string(i);
			int k = 0;
			for (int j = 0;j < value.size();j++) {
				k += value[j] - '0';
			}
			um[k]++;
			maxValue = max(maxValue, um[k]);
		}
		for (auto it = um.begin();it != um.end();it++) {
			if (it->second == maxValue) {
				res++;
			}
		}
		return res;
	}
};
上一篇:用TCP实现服务器与客户端的交互
下一篇:Redis Info 性能指标描述
相关推荐
clint456
4 天前
C++进阶(1)——前景提要
c++
夜悊
4 天前
C++代码示例:进制数简单生成工具
c++
郝学胜_神的一滴
4 天前
CMake 021: IF 条件判据详诠
c++·cmake
_wyt001
5 天前
洛谷 B3930 [GESP202312 五级] 烹饪问题 题解
c++·gesp
玖玥拾
5 天前
C/C++ 数据结构(七)栈、容器适配器
c语言·数据结构·c++·栈·容器适配器
один but you
5 天前
constexpr函数
c++
凡人叶枫
5 天前
Effective C++ 条款41:了解隐式接口和编译期多态
java·开发语言·c++·effective c++
凡人叶枫
5 天前
Effective C++ 条款42:了解 typename 的双重意义
java·linux·服务器·c++
小胖xiaopangss
5 天前
BRpc使用
c++·rpc
-森屿安年-
5 天前
63. 不同路径 II
c++·算法·动态规划
热门推荐
012026年6月AI大模型全景报告:GPT-5.6、Claude Opus 4.8、Gemini 3.5,中美AI三足鼎立谁主沉浮?022026年6月AI行业全景:从百模大战到Agent元年,这30天发生了什么?032026 年 AI 编程工具终极横评:Cursor vs Claude Code vs Copilot vs Windsurf04【AI】2026 年具身智能模型和世界模型总结05GitHub 镜像站点06AI科技热点日报 | 2026年6月1日07Claude Code、Codex、Cursor三分天下:2026年AI编程Agent生态全景剖析08AI一周事件 · 2026-06-03 至 2026-06-0909上线仅72小时被强制下架:Claude Fable 5 的短命10Codex 下载安装指南:Windows 和 macOS 官方版下载