Left most repetitive character in string in java

0

 



In this blog we will learn about how to print left most  repetitive character of string. In this we are given a string and we have to find the left most  repetitive character in java.



public class LeftmostRepeatingChar {

public static void main(String args[])
{
int arr[]=new int[26];
for(int i=0;i<26;i++)
{
arr[i]=0;
}
String str="hindicodingcommunity";
for(int i=0;i<str.length();i++)
{
if(arr[i]>0){
System.out.println(arr[i]);
break;
}
else
arr[str.charAt(i)-'a']+=i+1;
}
}
}

Post a Comment

0Comments
Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !