当前位置:网站首页>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] 1254 - count the number of closed Islands
- NBA player analysis
- Force deduction solution summary 2029 stone game IX
- PTA ladder game exercise set l2-001 inter city emergency rescue
- 怎样从微信返回的json字符串中截取某个key的值?
- Yolo format data set processing (XML to txt)
- Redux - detailed explanation
- 【LeetCode】977-有序数组的平方
- 士官类学校名录
- Loss function and positive and negative sample allocation: Yolo series
猜你喜欢

LeetCode刷题——统计各位数字都不同的数字个数#357#Medium

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

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

How to intercept the value of a key from the JSON string returned by wechat?

党史纪实主题公益数字文创产品正式上线

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

Equipped with Ti am62x processor, Feiling fet6254-c core board is launched!

17_ Redis_ Redis publish subscription

Download blender on Alibaba cloud image station

【网络安全】网络资产收集
随机推荐
LeetCode_ String_ Simple_ 412.Fizz Buzz
Custom exception
14_ Redis_ Optimistic lock
Case introduction and problem analysis of microservice
SQL transaction
Facing the challenge of "lack of core", how can Feiling provide a stable and strong guarantee for customers' production capacity?
士官类学校名录
[leetcode] 1020 number of enclaves
JVM architecture, classloader, parental delegation mechanism
Leetcode skimming -- incremental ternary subsequence 334 medium
自定义异常
Evaluation of embedded rz/g2l processor core board and development board of Feiling
[leetcode] 877 stone game
飞凌嵌入式RZ/G2L处理器核心板及开发板上手评测
Yolov5 code reproduction and server operation
Steps for Navicat to create a new database
12_ Redis_ Bitmap_ command
For the problem that Folium map cannot be displayed, the temporary solution is as follows
SQL stored procedure
工程师评测 | RK3568开发板上手测试