> For the complete documentation index, see [llms.txt](https://code-snippets.hbamithkumara.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://code-snippets.hbamithkumara.com/leetcode/problems/301-400/first-unique-character-in-a-string.md).

# 387. First Unique Character in a String

### Description

Given a string, find the first non-repeating character in it and return its index. If it doesn't exist, return -1.

**Note:** You may assume the string contains only lowercase English letters.

### Constraints

### Approach

### Links

* GeeksforGeeks
* [Leetcode](https://leetcode.com/problems/first-unique-character-in-a-string/)
* ProgramCreek
* YouTube

### **Examples**

{% tabs %}
{% tab title="Example 1" %}
**Input:** s = "leetcode"

**Output:** 0
{% endtab %}

{% tab title="Example 2" %}
**Input:** s = "loveleetcode"

**Output:** 2
{% endtab %}
{% endtabs %}

### **Solutions**

{% tabs %}
{% tab title="Solution 1" %}

```java
/**
 * Time complexity : 
 * Space complexity : 
 */

class Solution {
    public int firstUniqChar(String s) {
        if(s != null && s.length() != 0) {
            int[] count = new int[26];
            for(char ch: s.toCharArray()) {
                count[ch-'a']++;
            }
            for(int i = 0; i < s.length(); i++) {
                if(count[s.charAt(i)-'a'] == 1) {
                    return i;
                }
            }
        }
        return -1;
    }
}
```

{% endtab %}
{% endtabs %}

### **Follow up**

*
