Created
July 31, 2015 23:33
-
-
Save hoenn/18d3b2fb2c3315a80b5a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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