当前位置:网站首页>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 skimming -- incremental ternary subsequence 334 medium

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

LeetCode刷题——两整数之和#371#Medium

Guangzhou Emergency Management Bureau issued a high temperature and high humidity chemical safety reminder in July

03. Preliminary use of golang

SQL stored procedure

Wechat Alipay account system and payment interface business process

Solve the problem of frequent interruption of mobaxterm remote connection

Yolov5 code reproduction and server operation

LeetCode刷题——验证二叉树的前序序列化#331#Medium
随机推荐
2022 college students in Liaoning Province mathematical modeling a, B, C questions (related papers and model program code online disk download)
Solve the problem of frequent interruption of mobaxterm remote connection
Build your own semantic segmentation platform deeplabv3+
Real estate market trend outlook in 2022
. Solution to the problem of Chinese garbled code when net core reads files
6095. 强密码检验器 II
[leetcode] 417 - Pacific Atlantic current problem
Leetcode question brushing - parity linked list 328 medium
There are 7 seats with great variety, Wuling Jiachen has outstanding product power, large humanized space, and the key price is really fragrant
YOLOV5 代码复现以及搭载服务器运行
自定义异常
[leetcode] 695 - maximum area of the island
Beijing rental data analysis
2278. 字母在字符串中的百分比
03.golang初步使用
Bing. Site Internet
高考录取分数线爬取
How to find a sense of career direction
【网络安全】网络资产收集
Download blender on Alibaba cloud image station