全部评论
有没有大佬分享下解题思路啊![](https://uploadfiles.nowcoder.com/images/20220815/318889480_1660553763930/8B36D115CE5468E380708713273FEF43)
有人说一下第二是怎么写的吗
第一题: public int minOperations (String str) { // write code here int[] count = new int[26]; for (char ch : str.toCharArray()) { count[ch - 'a&(30185)#39;]++; } 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); }
第一题贪心,记录不存在的字母数量,遍历每个字母,优先考虑2个重复变成1个没有使用到的字母,如果所有字母都用过了,就2个重复变成1个自身;第二题,就是leetcode原题,把返回值改成列表,然后枚举每一种情况;第三题,后序遍历,返回2*max(左右节点权值)+1。
居然可以用ide!?
半个
有选择题嘛?
相关推荐
![](https://static.nowcoder.com/fe/file/oss/1716965564844UEBJN.png)
![](https://static.nowcoder.com/fe/file/oss/1716965585666UBBME.png)
TP-LINK
| 校招
| 超多精选岗位
点赞 评论 收藏
分享
01-06 04:55
重庆邮电大学 Java 点赞 评论 收藏
分享
昨天 13:38
广西职业技术学院 汽车制造其它 点赞 评论 收藏
分享