Skip to content

Commit 1e4713e

Browse files
authored
Update ArrayLeader.java
1 parent b4e47ca commit 1e4713e

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -1 +1,24 @@
1-
1+
public class ArrayLeader
2+
{
3+
public static void main(String[] args)
4+
{
5+
ArrayLeader obj = new ArrayLeader();
6+
int arr[] = {10, 4, 7, 2, 6, 3, 1};
7+
obj.leader(arr, arr.length);
8+
}
9+
10+
public void leader(int arr[], int size)
11+
{
12+
int max = arr[size - 1];
13+
System.out.print(max + " ");
14+
for(int i = size - 2; i >=0; i--)
15+
{
16+
if(max < arr[i])
17+
{
18+
System.out.print(arr[i] + " ");
19+
max = arr[i];
20+
}
21+
}
22+
}
23+
}
24+

0 commit comments

Comments
 (0)