Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

nearest greater to right

int[] arr = { 2, 4, 6, 2, 5 };
var stack = new Stack<int>();
var list = new List<int>();
for (int i = arr.Length - 1; i >= 0; i--)
{
	while( stack.Count > 0 && stack.Peek() < arr[i])
    {
    	stack.Pop();
    }
    list.Add(stack.Count == 0 ? -1 : stack.Peek());
    stack.Push(arr[i]);
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: unity print name of button when click on it 
Csharp :: delete file from FTP c# 
Csharp :: check strings is equal shell 
Csharp :: c# check if array is empty 
Csharp :: key press up unity 
Csharp :: get directory name of path c# 
Csharp :: unity making a coroutine wait until another coroutine is done 
Csharp :: c# how to check if two lists have same values 
Csharp :: c# round number 
Csharp :: waitforseconds unity 
Csharp :: unity destroy object invisible 
Csharp :: how to get the position of a camera in unity 
Csharp :: getname of month from date c# 
Csharp :: Prevent player rotation unity 
Csharp :: discord bot status code c# 
Csharp :: singleton unity 
Csharp :: c# how many lines in methods 
Csharp :: read input c# 
Csharp :: c# object to dictionary 
Csharp :: how to find a gameobject in unity 
Csharp :: unity 2d player move 
Csharp :: wpf set color in code 
Csharp :: c# create array 
Csharp :: unity 2d movement 
Csharp :: c# check if string is all numbers 
Csharp :: instantiate list with values c# 
Csharp :: unity detect keyboard not mouse 
Csharp :: how to write int array to console c# 
Csharp :: c# read file from directory 
Csharp :: exit button unity code 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =