import java.util.Scanner; public class Main6 { public static void main(String[] args){ Scanner in = new Scanner(System.in); while(in.hasNext()){ char[] cs = in.nextLine().toCharArray(); int n = cs.length; System.out.println(minPaint(cs, 0, n-1)); } } static int minPaint(char[] cs ,Integer start,int end){ int left = 0; int right = 0; int minLeft = 0; int minRight = 0; while(cs[start]=='R'&&start<end){ start++; } while(cs[end]=='G'&&end>start){ end--; } if(start>=end){ return 0; } while(cs[start+left]=='G'){ left++; } minLeft = left+minPaint(cs, start+left,end); while(cs[end-right]=='R'){ right++; } minRight = right+minPaint(cs, start, end-right); return Math.min(minLeft, minRight); } }
点赞 7

相关推荐

03-07 17:34
吉林大学 Java
野猪不是猪🐗:说说我的看法: 1. 分布式微服务不是必学的,先把mysql redis spring生态 juc jvm os 计网这些学的差不多,就能应对大部分常规八股。项目直接用单体项目也是可以的 2. 你的学历有优势,后续把外卖做个拓展换皮(或者去吃透一个不那么烂大街的项目),就能够收获不少面试。但重心建议放在八股算法上,项目不必追求高级或独特,但必须吃透,并且要提前准备一些话术,比如技术选型,为什么考虑用a而不是用b 3. 五六月份大厂暑期的难度会下降(因为大佬都选好offer开始释放了,很多甚至都入职了),所以心态要稳住,不要陷入内耗 加油
投递字节跳动等公司9个岗位
点赞 评论 收藏
分享
可以不说话:笔试a了3道半,今天说是挂了😭😭
投递汇丰科技等公司9个岗位
点赞 评论 收藏
分享
牛客网
牛客企业服务