leetcode 1556
简介
简单题
思路:sprintf 将数字转为字符串,然后新建一个空的字符串然后将逆序统计是否可以被3整除添加0
感觉简单题做的也很慢
参考链接
https://github.com/haoel/leetcode
https://github.com/lishaohsuai/leetCode
code
string thousandSeparator(int n) {
char str[100];
sprintf(str,"%d", n);
char strCopy[100];
int j = strlen(str);
int k = 0;
for(int i=0; str[i]!='\0';i++){
if((j-i) % 3 == 0 && i!=0){
strCopy[k] = '.';
k++;
}
strCopy[k] = str[i];
k++;
}
strCopy[k] = '\0';
printf("oldString %s\n", str);
string rlt(strCopy);
return rlt;
}
leetcode 1556的更多相关文章
- LeetCode.接雨水
题外话:LeetCode上一个测试用例总是通不过(我在文章末贴出通不过的测试用例),给的原因是超出运行时间,我拿那个测试用例试了下2.037ms运行完.我自己强行给加了这句: && m ...
- 我为什么要写LeetCode的博客?
# 增强学习成果 有一个研究成果,在学习中传授他人知识和讨论是最高效的做法,而看书则是最低效的做法(具体研究成果没找到地址).我写LeetCode博客主要目的是增强学习成果.当然,我也想出名,然而不知 ...
- LeetCode All in One 题目讲解汇总(持续更新中...)
终于将LeetCode的免费题刷完了,真是漫长的第一遍啊,估计很多题都忘的差不多了,这次开个题目汇总贴,并附上每道题目的解题连接,方便之后查阅吧~ 477 Total Hamming Distance ...
- [LeetCode] Longest Substring with At Least K Repeating Characters 至少有K个重复字符的最长子字符串
Find the length of the longest substring T of a given string (consists of lowercase letters only) su ...
- Leetcode 笔记 113 - Path Sum II
题目链接:Path Sum II | LeetCode OJ Given a binary tree and a sum, find all root-to-leaf paths where each ...
- Leetcode 笔记 112 - Path Sum
题目链接:Path Sum | LeetCode OJ Given a binary tree and a sum, determine if the tree has a root-to-leaf ...
- Leetcode 笔记 110 - Balanced Binary Tree
题目链接:Balanced Binary Tree | LeetCode OJ Given a binary tree, determine if it is height-balanced. For ...
- Leetcode 笔记 100 - Same Tree
题目链接:Same Tree | LeetCode OJ Given two binary trees, write a function to check if they are equal or ...
- Leetcode 笔记 99 - Recover Binary Search Tree
题目链接:Recover Binary Search Tree | LeetCode OJ Two elements of a binary search tree (BST) are swapped ...
- Leetcode 笔记 98 - Validate Binary Search Tree
题目链接:Validate Binary Search Tree | LeetCode OJ Given a binary tree, determine if it is a valid binar ...
随机推荐
- Linux部署调度工具xxl-job
背景: Pentaho Data Integration(kettle)作为用户规模最多的开源ETL工具,强大简洁的功能深受广大ETL从业者的欢迎.但kettle本身的调度监控功能却非常弱.Penta ...
- Spring基于xml的CRUD
目录 基于xml的CRUD 代码实现 测试 基于xml的CRUD 源码 使用C3P0连接池 使用dbutils包中的QueryRunner类来对数据库进行操作 代码实现 pom.xml <?xm ...
- 使用IDEA构建SpringBoot应用镜像
目录 前置设置 编写Dockerfile文件 添加运行配置 前置设置 确保IDEA已经设置了服务器Docker的信息.[1] 确保您有可运行的SpringBoot项目 编写Dockerfile文件 D ...
- 【翻译】Processing系列|(一)简介及使用方法
下一篇:[翻译]Processing系列|(二)安卓模式的安装使用及打包发布 下下篇:[翻译] Processing系列|(三)安卓项目构建 考虑到,学习啥都肯定要先读人家的官方文档,笔者把这个系列的 ...
- 【BUG】nuget restore遇到的两个报错“Failed to load msbuild Toolset”和“当前 .NET SDK 不支持将 .NET 6.0 设置为目标”
出错环境: Visual Studio 2019 1. Failed to load msbuild Toolset 解决:https://github.com/NuGet/Home/issues/4 ...
- 网络编程:阻塞I/O和进程模型
父进程和子进程 进程是程序执行的最小单位,一个进程有完整的地址空间.程序计数器等,如果想创建一个新的进程,使用函数 fork 就可以 pid_t fork(void) 返回:在子进程中为0,在父进程中 ...
- Kafka怎么配置SASL用户名密码认证
服务端配置(server.properties): # 开启SASL认证 security.protocol=SASL_PLAINTEXT sasl.mechanism=PLAIN # 配置JAAS文 ...
- 1-2 【包子mysql系列】, 对mysql的innoDB加锁分析
innoDB的事务,是基于锁来实现的,用到事务不自然就会用到锁,而如果对锁理解的不通透,很容易造成线上问题. 数据库加锁的分析,和事务的引擎,隔离级别,索引,主键索引都有关系, 如果去考虑引擎和各种隔 ...
- QJson出现“\n“变成“\\n“
在使用QJson的时候出现了字符串有\n的情况,在QJson转换为QByteArray的时候,\n变成了\n的情况,可以通过这样解决 int index = -1; do { index = qByt ...
- WebSocket 与 SSE 对比:即时通信的选择(一)
在现代 Web 开发中,实时通信需求越来越多,比如聊天应用.实时通知.直播弹幕.股票行情推送等.实现这些需求的常见技术有 WebSocket 和 SSE(Server-Sent Events),但它们 ...