当前位置:网站首页>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);
}
};边栏推荐
- Bing.com網站
- Leetcode skimming -- sum of two integers 371 medium
- 04. Some thoughts on enterprise application construction after entering cloud native
- 10_Redis_geospatial_命令
- 10_ Redis_ geospatial_ command
- How to intercept the value of a key from the JSON string returned by wechat?
- [leetcode] 1020 number of enclaves
- 【Experience Cloud】如何在VsCode中取得Experience Cloud的MetaData
- 6.12 企业内部upp平台(Unified Process Platform)的关键一刻
- 2022 年辽宁省大学生数学建模A、B、C题(相关论文及模型程序代码网盘下载)
猜你喜欢

Redux——详解

损失函数与正负样本分配:YOLO系列

【LeetCode】1905-统计子岛屿

【Experience Cloud】如何在VsCode中取得Experience Cloud的MetaData

Build your own semantic segmentation platform deeplabv3+

Yolo format data set processing (XML to txt)

Case introduction and problem analysis of microservice

百变大7座,五菱佳辰产品力出众,人性化大空间,关键价格真香

14_ Redis_ Optimistic lock

微信支付宝账户体系和支付接口业务流程
随机推荐
4. Data splitting of Flink real-time project
【LeetCode】1140-石子游戏II
[leetcode] 486 predict winners
MySQL calculate n-day retention rate
Leetcode skimming -- count the number of numbers with different numbers 357 medium
[leetcode] 189 rotation array
Thoroughly understand browser strong cache and negotiation cache
6091. 划分数组使最大差为 K
How to find a sense of career direction
18_ Redis_ Redis master-slave replication & cluster building
Yolov5 code reproduction and server operation
Evaluation of embedded rz/g2l processor core board and development board of Feiling
6095. 强密码检验器 II
Name of institution approved in advance
2022 college students in Liaoning Province mathematical modeling a, B, C questions (related papers and model program code online disk download)
【LeetCode】1254-统计封闭岛屿的数量
Solve the problem of frequent interruption of mobaxterm remote connection
(Video + graphic) machine learning introduction series - Chapter 5 machine learning practice
彻底弄懂浏览器强缓存和协商缓存
做好抗“疫”之路的把关人——基于RK3568的红外热成像体温检测系统