Skip to content

Instantly share code, notes, and snippets.

@hoenn
Created July 31, 2015 23:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hoenn/18d3b2fb2c3315a80b5a to your computer and use it in GitHub Desktop.
Save hoenn/18d3b2fb2c3315a80b5a to your computer and use it in GitHub Desktop.
public class firstUnique
{
public static void main()
{
System.out.println(findFirstUnique("aabbcc"));
System.out.println(findFirstUnique("abbcc"));
System.out.println(findFirstUnique("aabcc"));
System.out.println(findFirstUnique("aabbc"));
}
public static int findFirstUnique(String s)
{
for(int i = 0; i<s.length(); i++)
{
if(s.lastIndexOf(s.charAt(i))==s.indexOf(s.charAt(i)))
return i;
}
return -1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment