package com.fishercoder.solutions;

/**
 * 387. First Unique Character in a String
 * Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1.

 Examples:

 s = "leetcode"
 return 0.

 s = "loveleetcode",
 return 2.
 Note: You may assume the string contain only lowercase letters.

 */

public class _387 {

    public static int firstUniqChar(String s) {
        int[] freq = new int[26];
        for (int i = 0; i < s.length(); i++) {
            freq[s.charAt(i) - 'a']++;
        }
        for (int i = 0; i < s.length(); i++) {
            if (freq[s.charAt(i) - 'a'] == 1) {
                return i;
            }
        }
        return -1;
    }

    public static void main(String... strings) {
        String s = "leetcode";
        System.out.println(firstUniqChar(s));
    }

}

@@ -75,19 +75,16 @@
 a String
-%0A *
  Given a
@@ -133,16 +133,19 @@
 acter in
+%0A *
  it and 
@@ -195,17 +195,21 @@
 urn -1.%0A
-%0A
+ *%0A *
  Example
@@ -211,17 +211,21 @@
 amples:%0A
-%0A
+ *%0A *
  s = %22le
@@ -231,17 +231,16 @@
 eetcode%22
-%0A
  return 
@@ -242,17 +242,21 @@
 turn 0.%0A
-%0A
+ *%0A *
  s = %22lo
@@ -267,17 +267,16 @@
 etcode%22,
-%0A
  return 
@@ -277,17 +277,16 @@
 eturn 2.
-%0A
  Note: Y
@@ -342,17 +342,16 @@
 etters.%0A
-%0A
  */%0A%0Apub
@@ -367,16 +367,49 @@
  _387 %7B%0A
+  public static class Solution1 %7B
 %0A    pub
@@ -455,18 +455,16 @@
 %7B%0A      
-  
 int%5B%5D fr
@@ -483,26 +483,24 @@
 %5B26%5D;%0A      
- 
- 
 for (int i =
@@ -534,20 +534,16 @@
         
-  
-  
 freq%5Bs.c
@@ -563,30 +563,26 @@
 '%5D++;%0A      
-  %7D%0A  
+%7D%0A
       for (i
@@ -622,20 +622,16 @@
         
- 
-   
 if (freq
@@ -668,22 +668,16 @@
         
-      
 return i
@@ -678,20 +678,16 @@
 turn i;%0A
-    
         
@@ -690,30 +690,26 @@
     %7D%0A      
-  %7D%0A  
+%7D%0A
       return
@@ -723,140 +723,10 @@
   %7D%0A
-%0A    public static void main(String... strings) %7B%0A        String s = %22leetcode%22;%0A        System.out.println(firstUniqChar(s));%0A  
   %7D%0A
-%0A
 %7D%0A

refactor 387