首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

Java 刷题(八)

Codewars 刷题第八天,数字问题:

题目开始之前,先分享第七期的答案:

第七期题目:

In a factory a printer prints labels for boxes. For one kind of boxes the printer has to use colors which, for the sake of simplicity, are named with letters from.

The colors used by the printer are recorded in a control string. For example a "good" control string would bemeaning that the printer used three times color a, four times color b, one time color h then one time color a...

Sometimes there are problems: lack of colors, technical malfunction and a "bad" control string is produced e.g..

You have to write a functionwhich given a string will output the error rate of the printer as astringrepresenting a rational whose numerator is the number of errors and the denominator the length of the control string. Don't reduce this fraction to a simpler expression.

The string has a length greater or equal to one and contains only letters fromto.

#Examples:

答案:(已AC)

1.

2.

3.

这是三个解决方案,不过其思路是各不相同的1是较为通常的检索遍历,返回字符串(此处也可以如同2中的返回方式,默认强制转换为字符串类型),2中的chars()函数与filter()函数也是比较通用的,详见下图,3中replaceAll() 中的参数可以用[char,char]的方式表示范围。

filter() 是过滤器通常在使用的过程中()内参数为ch->判断形式的一种约束。

第八期题目:

题目要求:

很简单,将数组中的按顺序排放的字母中间缺少的内容找出来,并返回。

解析:

遍历,校验当前的(除第一个外)是否为上一个的ACII码值加1;不是则返回加1的字母。

同样明晚之前上传答案!

喜欢的朋友不妨加个关注,交个朋友!一起分享身边的故事和学习!

  • 发表于:
  • 原文链接http://kuaibao.qq.com/s/20180424G00PUE00?refer=cp_1026
  • 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。
  • 如有侵权,请联系 cloudcommunity@tencent.com 删除。

扫码

添加站长 进交流群

领取专属 10元无门槛券

私享最新 技术干货

扫码加入开发者社群
领券