Skip to content

Commit

Permalink
Merge pull request #3673 from NotADucc/1963
Browse files Browse the repository at this point in the history
create 1963-minimum-number-of-swaps-to-make-the-string-balanced.cs
  • Loading branch information
Ykhan799 authored Oct 12, 2024
2 parents f935e60 + caa375e commit f5bf87b
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions csharp/1963-minimum-number-of-swaps-to-make-the-string-balanced.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
public class Solution
{
public int MinSwaps(string s)
{
int open_braces = 0, swaps = 0;
foreach (var ch in s)
{
if (ch == '[')
{
open_braces++;
}
else
{
if (open_braces <= 0)
{
open_braces++;
swaps++;
}
else
{
open_braces--;
}
}
}

return swaps;
}
}

0 comments on commit f5bf87b

Please sign in to comment.