387. First unique character in the String | Leetcode problem Tamil Solution

Опубликовано: 03 Август 2026
на канале: siya_tech_tales
603
18

Follow us on Instagram: https://www.instagram.com/siyatechtal...
-----------------------
Explanation:
Loop Through Each Character:

Use a for loop to iterate over the string s character by character.
Check for Uniqueness:

Use s.indexOf(c) to find the first occurrence of the character c.
Use s.lastIndexOf(c) to find the last occurrence of the character c.
If both indices are the same, it means the character is not repeated in the string.
Return the Index:

As soon as a unique character is found, return its index.
Handle the Case When No Unique Character Exists:

If no unique character is found after iterating through the entire string, return -1.
Example Run:
Input: "loveleetcode"

'l': indexOf('l') = 0, lastIndexOf('l') = 0 → Unique, return 0.
Input: "aabb"

No character satisfies the uniqueness condition → Return -1.
This solution is simple, clear, and uses only basic concepts!
-----------------------
Copyright Disclaimer under Section 52 of the Copyright Act, 1957 (India):
This video is made for educational, informational, and entertainment purposes only. The content is transformative in nature, and its use is considered fair use under Indian copyright law. No copyright infringement is intended, and all rights belong to their respective owners. The purpose of this video is to educate, inform, and entertain, and it is not intended to harm or exploit any individual or entity. If you have any concerns or objections, please contact us at [email protected]

#leetcodejava
#coding
#leetcode