当前位置:网站首页>2278. Percentage of letters in string
2278. Percentage of letters in string
2022-07-02 15:40:00 【Laver (nori)】
problem :
Why? , When in the code times Variable is float The type is , perform case You get the wrong results ?
class Solution {
public:
int percentageLetter(string s, char letter) {
// Floating point numbers are used here , It is convenient to divide floating-point numbers
/* Note:
If you use float Type change the result to int Time will lead to the result minus one
case: times = 59; size = 100, return 58
*/
// The number of times letters appear
double times = 0;
for(int i = 0; i < s.size(); i++){
if(s[i] == letter){
times++;
}
}
// Expand the results 100 The decimal part is removed again , This requires downward evidence
return (int)((times/s.size())*100);
}
};边栏推荐
- [development environment] install the Chinese language pack for the 2013 version of visual studio community (install test agents 2013 | install visual studio 2013 simplified Chinese)
- Leetcode question brushing - parity linked list 328 medium
- folium,确诊和密接轨迹上图
- 【网络安全】网络资产收集
- 15_ Redis_ Redis. Conf detailed explanation
- 【LeetCode】189-轮转数组
- SQL stored procedure
- 10_ Redis_ geospatial_ command
- 【LeetCode】344-反转字符串
- folium地图无法显示的问题,临时性解决方案如下
猜你喜欢

19_ Redis_ Manually configure the host after downtime

Custom exception

LeetCode刷题——奇偶链表#328#Medium

【LeetCode】1254-统计封闭岛屿的数量

There are 7 seats with great variety, Wuling Jiachen has outstanding product power, large humanized space, and the key price is really fragrant

MySQL -- Index Optimization -- order by

10_ Redis_ geospatial_ command

Evaluation of embedded rz/g2l processor core board and development board of Feiling

I made an istio workshop. This is the first introduction

Bing. Site Internet
随机推荐
Storage read-write speed and network measurement based on rz/g2l | ok-g2ld-c development board
FPGA - 7系列 FPGA内部结构之Clocking -03- 时钟管理模块(CMT)
[leetcode] 1254 - count the number of closed Islands
Leetcode skimming - remove duplicate letters 316 medium
【LeetCode】877-石子游戏
Pytoch saves tensor to Mat file
16_ Redis_ Redis persistence
[leetcode] 876 intermediate node of linked list
PTA ladder game exercise set l2-001 inter city emergency rescue
【LeetCode】577-反转字符串中的单词 III
Build your own semantic segmentation platform deeplabv3+
[leetcode] 1020 number of enclaves
5. Practice: jctree implements the annotation processor at compile time
Pytorch 保存tensor到.mat文件
Redux - detailed explanation
搭建自己的语义分割平台deeplabV3+
LeetCode刷题——两整数之和#371#Medium
Bing. Site Internet
11_ Redis_ Hyperloglog_ command
14_ Redis_ Optimistic lock