楼主:
oin1104 (是oin的说)
2024-10-08 16:08:391963.
题目:
有一群[ ]
你可以交换他们的位子
最少几次交换可以让他左右括号都匹配
思路:
用two pointer在两边纪录左右括号的数量
有缺的话就去其他地方拿并记录次数
```cpp
class Solution {
public:
int minSwaps(string s)
{
int res = 0;
int n = s.size();
int l = 0 ;
int r = n-1;
int lcnt = 0;
int rcnt = 0;
while(l<r)
{
if(s[l] == '[')lcnt ++;
else lcnt
Links booklink
Contact Us: admin [ a t ] ucptt.com