Run Code
|
API
|
Code Wall
|
Users
|
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
Please
log in
to post a comment.
Integers Array manipulation examples
hacktonxx
Reed Solomon Demo
30272 Program Ex7_1 switch_int
RightSideView Tree
D12
Interface
FREE V-BUCKS GENERATOR NO HUMAN VERIFICATION 2022 [zT4]
decimal to binary
asdfghjujyhtgrfed
Please log in to post a comment.