1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-10-18 14:52:09 +02:00

java: add «1963. Minimum Number of Swaps to Make the String Balanced»

URL:	https://leetcode.com/problems/minimum-number-of-swaps-to-make-the-string-balanced/
Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
Matej Focko 2024-10-08 20:06:44 +02:00
parent 1f69732126
commit 1b43a2fe51
Signed by: mfocko
SSH key fingerprint: SHA256:icm0fIOSJUpy5+1x23sfr+hLtF9UhY8VpMC7H4WFJP8

View file

@ -0,0 +1,22 @@
class Solution {
public int minSwaps(String s) {
var open = 0;
for (var c : s.toCharArray()) {
switch (c) {
case '[':
++open;
break;
case ']':
if (open > 0) {
--open;
}
break;
default:
/* no-op */
break;
}
}
return (1 + open) / 2;
}
}