当前位置:网站首页>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);
}
};
边栏推荐
- 2022 college students in Liaoning Province mathematical modeling a, B, C questions (related papers and model program code online disk download)
- Bing. Com website
- Semantic segmentation learning notes (1)
- College entrance examination admission score line crawler
- Markdown tutorial
- 16_ Redis_ Redis persistence
- Custom exception
- 4. Data splitting of Flink real-time project
- PTA ladder game exercise set l2-001 inter city emergency rescue
- 10_ Redis_ geospatial_ command
猜你喜欢
JVM architecture, classloader, parental delegation mechanism
Yolov5 code reproduction and server operation
Let your HMI have more advantages. Fet-g2ld-c core board is a good choice
FPGA - 7系列 FPGA内部结构之Clocking -03- 时钟管理模块(CMT)
【LeetCode】417-太平洋大西洋水流问题
[leetcode] 417 - Pacific Atlantic current problem
Facing the challenge of "lack of core", how can Feiling provide a stable and strong guarantee for customers' production capacity?
Leetcode question brushing - parity linked list 328 medium
Party History Documentary theme public welfare digital cultural and creative products officially launched
Beijing rental data analysis
随机推荐
【LeetCode】189-轮转数组
04. Some thoughts on enterprise application construction after entering cloud native
6091. 划分数组使最大差为 K
yolo格式数据集处理(xml转txt)
【LeetCode】1254-统计封闭岛屿的数量
Custom exception
4. Jctree related knowledge learning
Markdown tutorial
【Experience Cloud】如何在VsCode中取得Experience Cloud的MetaData
How does the computer set up speakers to play microphone sound
高考录取分数线爬取
微信支付宝账户体系和支付接口业务流程
Name of institution approved in advance
Case introduction and problem analysis of microservice
[leetcode] 1254 - count the number of closed Islands
MySQL -- Index Optimization -- order by
folium地图无法显示的问题,临时性解决方案如下
[leetcode] 344 reverse string
JVM architecture, classloader, parental delegation mechanism
For the problem that Folium map cannot be displayed, the temporary solution is as follows