当前位置:网站首页>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);
}
};边栏推荐
- [leetcode] 344 reverse string
- LeetCode刷题——两整数之和#371#Medium
- . Solution to the problem of Chinese garbled code when net core reads files
- NBA player analysis
- 彻底弄懂浏览器强缓存和协商缓存
- 【LeetCode】486-预测赢家
- 面对“缺芯”挑战,飞凌如何为客户产能提供稳定强大的保障?
- 4. Data splitting of Flink real-time project
- 【LeetCode】19-删除链表的倒数第N个结点
- How to avoid 7 common problems in mobile and network availability testing
猜你喜欢
随机推荐
飞凌嵌入式RZ/G2L处理器核心板及开发板上手评测
【LeetCode】200-岛屿数量
LeetCode刷题——去除重复字母#316#Medium
11_ Redis_ Hyperloglog_ command
【网络安全】网络资产收集
自定义异常
基于RZ/G2L | OK-G2LD-C开发板存储读写速度与网络实测
JVM architecture, classloader, parental delegation mechanism
5. Practice: jctree implements the annotation processor at compile time
Folium, diagnosis and close contact trajectory above
10_Redis_geospatial_命令
6095. 强密码检验器 II
损失函数与正负样本分配:YOLO系列
【LeetCode】877-石子游戏
2022 college students in Liaoning Province mathematical modeling a, B, C questions (related papers and model program code online disk download)
[leetcode] 577 reverse word III in string
LeetCode_ String_ Simple_ 412.Fizz Buzz
SQL transaction
语义分割学习笔记(一)
Infra11199 database system




![[leetcode] 1254 - count the number of closed Islands](/img/84/f888ae0e164951cd9623fb3bf4a984.png)




