Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

remove adjacent duplicate characters

	public static string GreatSolution(string s, int k)
    {
        Stack<int[]> stack = new Stack<int[]>();

        foreach (char ch in s.ToCharArray())
        {
            if (stack.Count!=0 && stack.Peek()[0] == ch)
                stack.Peek()[1]++;
            else 
              	stack.Push(new int[] { ch, 1 });
          
            if (stack.Peek()[1] == k) 
              	stack.Pop();
        }
        var sb = string.Empty;
        while (stack.Count>0)
        {
            int[] top = stack.Pop();
          
            while (top[1]-- > 0)
                sb = ((char)top[0]).ToString() +sb;
        }
        return sb.ToString();
    }
// put the value of k as per required
Comment

PREVIOUS NEXT
Code Example
Csharp :: what is the meaning of ?? in c# 
Csharp :: average c# 
Csharp :: how to make text show a variable in unity 
Csharp :: c# how to fill a datatable 
Csharp :: find character from string c# count 
Csharp :: coroutine start unity 
Csharp :: how to check that string has only alphabet in c# 
Csharp :: merge xml files into one c# 
Csharp :: c# mongodb update multiple fields 
Csharp :: unity color by rgb 
Csharp :: unity sound 
Csharp :: Task.FromResult(null) 
Csharp :: C# program that joins List of strings 
Csharp :: length of array c# unity 
Csharp :: c# how does comparing datetime work 
Csharp :: c# ienumerable to list 
Csharp :: get property value from object c# 
Csharp :: array in c# stack overflow 
Csharp :: change working directory shell 
Csharp :: integer required asp.net core 
Csharp :: unity 2d 
Csharp :: datetime empty date 
Csharp :: xamarin picker 
Csharp :: get file path in .net core from wwwroot folder 
Csharp :: system.net.mail send html message 
Csharp :: c# close program 
Csharp :: get selected item datagrid wpf 
Csharp :: how to minimum text length in textbox in c# 
Csharp :: if viewbag is null 
Csharp :: make 2D object move at constant speed unity 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =