leetcode 1624. 两个相同字符之间的最长子字符串-耗时100

张开发
2026/4/7 15:39:23 15 分钟阅读

分享文章

leetcode 1624. 两个相同字符之间的最长子字符串-耗时100
Problem: 1624. 两个相同字符之间的最长子字符串耗时100%双指针找到相同的以后直接break以及拿到最大值Codeclass Solution { public: int maxLengthBetweenEqualCharacters(string s) { int n s.size(), mx -1; char ch; for(int i 0; i n; i) { ch s[i]; for(int j n - 1; j 0; j--) { if(ch s[j]) { mx max(mx, j - i); break; } } } return mx-1; } };

更多文章