mirror of
https://github.com/lWolvesl/leetcode.git
synced 2026-01-13 02:38:37 +08:00
init
This commit is contained in:
25
23/11/Q2609.h
Normal file
25
23/11/Q2609.h
Normal file
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// Created by 李洋 on 2023/11/8.
|
||||
//
|
||||
|
||||
#ifndef LEECODE_C_Q2609_H
|
||||
#define LEECODE_C_Q2609_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <stack>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int findTheLongestBalancedSubstring(string s) {
|
||||
int n = s.size(), idx = 0, ans = 0;
|
||||
while (idx < n) {
|
||||
int a = 0, b = 0;
|
||||
while (idx < n && s[idx] == '0' && ++a >= 0) idx++;
|
||||
while (idx < n && s[idx] == '1' && ++b >= 0) idx++;
|
||||
ans = max(ans, min(a, b) * 2);
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
|
||||
#endif //LEECODE_C_Q2609_H
|
||||
Reference in New Issue
Block a user