Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
1stoccuinsorted
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static int Find1stOccurence(int [] arr, int num) { int l=0;int h= arr.Length-1; while( l < h) { int mid = (l+h)/2; if(arr[mid]==num) { if(arr[mid-1] == num) { int k=mid-1; while(arr[mid] != arr[k]) { k--; } return k; } else { return mid; } } if (arr[mid]>num) { h=mid-1; } if(arr[mid]<num) { l=mid+1; } } return -1; } public static void Main(string[] args) { int [] arr = {1,2,2,3,3,4,4,5,5,6}; Console.WriteLine(Find1stOccurence(arr,4)); } } }
run
|
edit
|
history
|
help
0
TestCodec1
RegularExpressions
reverse a stack
The abstract factory design pattern implemented in c# using generics.
abebe
c++
sdfgthyjukiujyhtgrf
*271*271#
Fibonacci Modified
Armstrong