第一题: public int minOperations (String str) { // write code here int[] count = new int[26]; for (char ch : str.toCharArray()) { count[ch - 'a']++; } int ans = 0; int sum = 0; for (int i = 0; i < 26; i++) { ans += count[i] / 2; count[i] %= 2; sum += count[i]; } if (ans + sum < 26) { return ans; } return ans + ans - (26 - sum); }
3 3

相关推荐

码农索隆:这种hr,建议全中国推广
点赞 评论 收藏
分享
06-16 15:04
黑龙江大学 Java
零OFFER战士:另一个版本查看图片
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务