question_slug stringlengths 3 77 | title stringlengths 1 183 | slug stringlengths 12 45 | summary stringlengths 1 160 ⌀ | author stringlengths 2 30 | certification stringclasses 2
values | created_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | updated_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | hit_count int64 0 10.6M | has_video bool 2
classes | content stringlengths 4 576k | upvotes int64 0 11.5k | downvotes int64 0 358 | tags stringlengths 2 193 | comments int64 0 2.56k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
first-unique-character-in-a-string | Simple Python | simple-python-by-etherealoptimist-vuls | \nclass Solution:\n def firstUniqChar(self, s):\n d = {}\n seen = set()\n for idx, c in enumerate(s):\n if c not in seen:\n | etherealoptimist | NORMAL | 2018-09-11T22:16:41.899114+00:00 | 2018-09-11T22:16:41.899167+00:00 | 20,945 | false | ```\nclass Solution:\n def firstUniqChar(self, s):\n d = {}\n seen = set()\n for idx, c in enumerate(s):\n if c not in seen:\n d[c] = idx\n seen.add(c)\n elif c in d:\n del d[c]\n return min(d.values()) if d else -1\n``` | 92 | 2 | [] | 11 |
first-unique-character-in-a-string | Very Easy || 100% || Fully Explained || Java, C++, Python, JavaScript, Python3 | very-easy-100-fully-explained-java-c-pyt-0pcq | Java Solution:\n\nclass Solution {\n public int firstUniqChar(String s) {\n // Base case...\n if(s.length() == 0) return -1;\n // To ke | PratikSen07 | NORMAL | 2022-08-29T15:03:07.513946+00:00 | 2022-08-29T15:05:27.840391+00:00 | 23,712 | false | # **Java Solution:**\n```\nclass Solution {\n public int firstUniqChar(String s) {\n // Base case...\n if(s.length() == 0) return -1;\n // To keep track of the count of each character, we initialize an int[]store with size 26...\n int[] store = new int[26];\n // Traverse string to... | 86 | 0 | ['String', 'Queue', 'C', 'Python', 'Java', 'Python3', 'JavaScript'] | 13 |
first-unique-character-in-a-string | C++ O(n) 4 Lines solution, Beats 97% | c-on-4-lines-solution-beats-97-by-sherla-ul7w | \nclass Solution {\npublic:\n int firstUniqChar(string s) {\n vector<int> v(26,0);\n\t\tfor(char c : s) v[c - \'a\']++;\n\t\tfor(int i = 0; i < s.leng | sherlasd | NORMAL | 2020-02-20T15:51:16.595671+00:00 | 2020-03-05T20:09:01.717696+00:00 | 15,520 | false | ```\nclass Solution {\npublic:\n int firstUniqChar(string s) {\n vector<int> v(26,0);\n\t\tfor(char c : s) v[c - \'a\']++;\n\t\tfor(int i = 0; i < s.length(); i++){\n\t\t\tif(v[s[i] - \'a\'] == 1) return i;\n\t\t}\n\t\treturn -1;\n }\n};\n``` | 86 | 3 | ['C', 'C++'] | 12 |
first-unique-character-in-a-string | Java Simple "Another thought" | java-simple-another-thought-by-santanu_3-hudx | ```java\n\n public int firstUniqChar(String s) {\n for(char c : s.toCharArray()){\n int index = s.indexOf(c);\n int lastIndex = | santanu_33 | NORMAL | 2020-06-19T09:41:27.792520+00:00 | 2020-06-19T09:45:47.273567+00:00 | 7,646 | false | ```java\n\n public int firstUniqChar(String s) {\n for(char c : s.toCharArray()){\n int index = s.indexOf(c);\n int lastIndex = s.lastIndexOf(c);\n if(index == lastIndex)\n return index;\n }\n return -1;\n }\n//runtime O(n^2) | 80 | 2 | ['Java'] | 15 |
first-unique-character-in-a-string | 5 Lines of Code in Two Methods | 5-lines-of-code-in-two-methods-by-ganjin-3slq | \n\n# 1. Count the first occurence one and break loop\n\nclass Solution:\n def firstUniqChar(self, s: str) -> int:\n for i,c in enumerate(s):\n | GANJINAVEEN | NORMAL | 2023-03-21T20:50:02.833536+00:00 | 2023-03-21T20:50:02.833581+00:00 | 9,732 | false | \n\n# 1. Count the first occurence one and break loop\n```\nclass Solution:\n def firstUniqChar(self, s: str) -> int:\n for i,c in enumerate(s):\n if s.count(c)==1:\n return i\n break\n return -1\n #please upvote me it would encourage me alot\n\n```\n# 2. Usi... | 59 | 1 | ['Python3'] | 9 |
first-unique-character-in-a-string | ✅☑Beats 100% Users || Easy Understood Solution with optimized space || 3 Approaches🔥 | beats-100-users-easy-understood-solution-6evx | \n\n# brute-force approach: \n - Initialization:\n - Get the length of the input string s and store it in the variable n.\n - Main Loop:\n - Iterate thr | MindOfshridhar | NORMAL | 2024-02-05T02:05:41.422545+00:00 | 2024-02-05T02:48:16.965286+00:00 | 10,283 | false | \n\n# brute-force approach: \n - Initialization:\n - Get the length of the input string s and store it in the variable n.\n - Main Loop:\n - Iterate through each character in the string using the in... | 56 | 2 | ['Hash Table', 'String', 'Dynamic Programming', 'Queue', 'Counting', 'Python', 'C++', 'Java', 'Python3', 'JavaScript'] | 6 |
first-unique-character-in-a-string | [ Python ] ✅✅ Simple Python Solution With Two Approach 🥳✌👍 | python-simple-python-solution-with-two-a-1bb9 | If You like the Solution, Don\'t Forget To UpVote Me, Please UpVote! \uD83D\uDD3C\uD83D\uDE4F\n# Approach 1: - Iterative \n# Runtime: 89 ms, faster than 67.59% | ashok_kumar_meghvanshi | NORMAL | 2022-02-23T06:36:33.395875+00:00 | 2024-02-05T06:20:37.386964+00:00 | 5,834 | false | # If You like the Solution, Don\'t Forget To UpVote Me, Please UpVote! \uD83D\uDD3C\uD83D\uDE4F\n# Approach 1: - Iterative \n# Runtime: 89 ms, faster than 67.59% of Python3 online submissions for First Unique Character in a String.\n# Memory Usage: 16.7 MB, less than 66.48% of Python3 online submissions for First Uniqu... | 53 | 0 | ['Iterator', 'Python', 'Python3'] | 2 |
first-unique-character-in-a-string | My Javascript Solution | my-javascript-solution-by-miryang-l8sy | \nvar firstUniqChar = function(s) {\n for(i=0; i<s.length; i++)\n if(s.indexOf(s[i])===s.lastIndexOf(s[i])) return i\n return -1\n};\n | miryang | NORMAL | 2019-08-29T04:12:34.628594+00:00 | 2019-08-29T04:12:34.628631+00:00 | 6,347 | false | ```\nvar firstUniqChar = function(s) {\n for(i=0; i<s.length; i++)\n if(s.indexOf(s[i])===s.lastIndexOf(s[i])) return i\n return -1\n};\n``` | 51 | 4 | ['JavaScript'] | 9 |
first-unique-character-in-a-string | Python - Simple Solution | python-simple-solution-by-nuclearoreo-xm0x | \nclass Solution:\n def firstUniqChar(self, s: str) -> int:\n d = {}\n for l in s:\n if l not in d: d[l] = 1\n else: d[l] | nuclearoreo | NORMAL | 2019-08-10T03:52:09.292732+00:00 | 2019-08-10T03:52:09.292797+00:00 | 12,232 | false | ```\nclass Solution:\n def firstUniqChar(self, s: str) -> int:\n d = {}\n for l in s:\n if l not in d: d[l] = 1\n else: d[l] += 1\n \n index = -1\n for i in range(len(s)):\n if d[s[i]] == 1:\n index = i\n break\n ... | 47 | 3 | ['Python', 'Python3'] | 10 |
first-unique-character-in-a-string | my 4 lines Java solution | my-4-lines-java-solution-by-lindsayling-tg39 | ```\npublic static int firstUniqChar(String s) {\n \n\t\tchar[] a = s.toCharArray();\n\t\t\n\t\tfor(int i=0; i<a.length;i++){\n\t\t\tif(s.indexOf(a[i])== | lindsayling | NORMAL | 2016-08-27T20:25:35.125000+00:00 | 2018-10-07T01:14:20.334798+00:00 | 17,756 | false | ```\npublic static int firstUniqChar(String s) {\n \n\t\tchar[] a = s.toCharArray();\n\t\t\n\t\tfor(int i=0; i<a.length;i++){\n\t\t\tif(s.indexOf(a[i])==s.lastIndexOf(a[i])){return i;}\n\t\t}\n\t\treturn -1;\n } | 45 | 10 | [] | 16 |
first-unique-character-in-a-string | ✅ 🔥 0 ms Runtime Beats 100% User confirm 🔥|| Step By Steps Solution ✅ || Beginner Friendly ✅ | | 0-ms-runtime-beats-100-user-confirm-step-09tz | \u2705 IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE AT THE END \u2705 :\n\n### Intuition:\nTo find the first non-repeating character in a string, we need to determ | Letssoumen | NORMAL | 2024-11-17T02:58:25.628595+00:00 | 2024-11-17T02:58:25.628626+00:00 | 10,876 | false | \u2705 IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE AT THE END \u2705 :\n\n### Intuition:\nTo find the first non-repeating character in a string, we need to determine the frequency of each character and then identify the first character with a frequency of 1. This can be efficiently achieved using a single pass to count f... | 43 | 0 | ['Hash Table', 'String', 'C++', 'Java', 'Python3'] | 3 |
first-unique-character-in-a-string | Java two pointers (slow and fast) solution (18 ms) | java-two-pointers-slow-and-fast-solution-6wgv | The idea is to use a slow pointer to point to the current unique character and a fast pointer to scan the string. The fast pointer not only just add the count o | yubad2000 | NORMAL | 2016-08-23T04:13:51.708000+00:00 | 2018-09-19T20:29:15.179815+00:00 | 30,961 | false | The idea is to use a slow pointer to point to the current unique character and a fast pointer to scan the string. The fast pointer not only just add the count of the character. Meanwhile, when fast pointer finds the identical character of the character at the current slow pointer, we move the slow pointer to the next u... | 42 | 1 | [] | 16 |
first-unique-character-in-a-string | Javascript Simple 2 Iterations (hash, search) | javascript-simple-2-iterations-hash-sear-8et8 | \nvar firstUniqChar = function(s) {\n let map = {}\n \n for (let char of s) {\n map[char] ? map[char]++ : map[char] = 1\n }\n \n for (l | cu6upb | NORMAL | 2020-01-07T05:19:52.683371+00:00 | 2020-01-07T05:19:52.683422+00:00 | 4,687 | false | ```\nvar firstUniqChar = function(s) {\n let map = {}\n \n for (let char of s) {\n map[char] ? map[char]++ : map[char] = 1\n }\n \n for (let i = 0; i < s.length; i++) {\n if (map[s[i]] === 1) return i\n }\n \n return -1\n};\n``` | 36 | 0 | ['JavaScript'] | 5 |
first-unique-character-in-a-string | Python 4 Lines, beats 98% ~52ms | python-4-lines-beats-98-52ms-by-deepgosa-7kxq | \nfrom collections import OrderedDict, Counter\nclass Solution:\n def firstUniqChar(self, s: str) -> int:\n\t# Explaination: Ordered Dict will save the chara | deepgosalia1 | NORMAL | 2020-05-17T17:16:04.508983+00:00 | 2022-11-16T22:04:14.610911+00:00 | 5,425 | false | ```\nfrom collections import OrderedDict, Counter\nclass Solution:\n def firstUniqChar(self, s: str) -> int:\n\t# Explaination: Ordered Dict will save the characters it encounters in\n\t# same sequence as the original string. Hence it becomes easy to catch hold of the first\n\t#unique character. Then according to th... | 34 | 0 | ['Python', 'Python3'] | 7 |
first-unique-character-in-a-string | ✅Short || C++ || Java || PYTHON || Explained Solution✔️ || Beginner Friendly ||🔥 🔥 BY MR CODER | short-c-java-python-explained-solution-b-iisf | Please UPVOTE if you LIKE!!\nWatch this video \uD83E\uDC83 for the better explanation of the code.\n\nhttps://www.youtube.com/watch?v=HVmq6apu3Zk\n\n\nAlso you | mrcoderrm | NORMAL | 2022-08-16T04:04:38.699089+00:00 | 2022-08-16T09:37:08.214459+00:00 | 6,965 | false | **Please UPVOTE if you LIKE!!**\n**Watch this video \uD83E\uDC83 for the better explanation of the code.**\n\nhttps://www.youtube.com/watch?v=HVmq6apu3Zk\n\n\n**Also you can SUBSCRIBE \uD83E\uDC81 \uD83E\uDC81 \uD83E\uDC81 this channel for the daily leetcode challange solution.**\n\n\n**C++**\n```\nclass Solution {\np... | 28 | 3 | ['C', 'Python', 'C++', 'Java'] | 5 |
first-unique-character-in-a-string | 1-liners in Python, 76ms | 1-liners-in-python-76ms-by-o_sharp-mz2c | \nclass Solution(object):\n def firstUniqChar(self, s):\n return min([s.find(c) for c in string.ascii_lowercase if s.count(c)==1] or [-1])\n\nIt gave | o_sharp | NORMAL | 2016-08-22T08:04:31.003000+00:00 | 2016-08-22T08:04:31.003000+00:00 | 16,329 | false | ```\nclass Solution(object):\n def firstUniqChar(self, s):\n return min([s.find(c) for c in string.ascii_lowercase if s.count(c)==1] or [-1])\n```\nIt gave me 76ms.\n\nOr\n```\nclass Solution(object):\n def firstUniqChar(self, s):\n return min([s.find(c) for c,v in collections.Counter(s).iteritems()... | 27 | 2 | [] | 6 |
first-unique-character-in-a-string | 🔥 Python || Easily Understood ✅ || Faster than 99.7% || 5 Lines | python-easily-understood-faster-than-997-yasj | Appreciate if you could upvote this solution\n\nCode:\n\ndef firstUniqChar(self, s: str) -> int:\n\tchr_count = Counter(s)\n\tfor x in chr_count:\n\t\tif chr_co | wingskh | NORMAL | 2022-08-16T02:56:13.381411+00:00 | 2022-08-16T03:04:33.620126+00:00 | 2,256 | false | **Appreciate if you could upvote this solution**\n\nCode:\n```\ndef firstUniqChar(self, s: str) -> int:\n\tchr_count = Counter(s)\n\tfor x in chr_count:\n\t\tif chr_count[x] == 1:\n\t\t\treturn s.index(chr_count[x])\n\treturn -1\n```\n\n**Time Complexity**: `O(n)`\n**Space Complexity**: `O(n)` | 26 | 0 | ['Python'] | 3 |
first-unique-character-in-a-string | C++✅ || Beats 100%💯|| 4 Lines Code💀💯|| EasyPizyy🔥💯 | c-beats-100-4-lines-code-easypizyy-by-ya-f9tb | 💡 IntuitionTo find the first unique character in a string, we need to determine the first character that appears only once. 🔍🛠️ Approach
📌 Use an unordered_map | yashm01 | NORMAL | 2025-02-10T03:43:38.677080+00:00 | 2025-02-10T03:43:38.677080+00:00 | 2,342 | false | # 💡 Intuition
To find the **first unique character** in a string, we need to determine the first character that appears **only once**. 🔍
# 🛠️ Approach
1. 📌 Use an **unordered_map** to store the frequency of each character.
2. 🔄 Iterate through the string to **count occurrences** of each character.
3. 🚀... | 24 | 0 | ['Hash Table', 'String', 'Queue', 'Counting', 'C++'] | 0 |
first-unique-character-in-a-string | ✅ Three Java Simple Solution | three-java-simple-solution-by-ahmedna126-drb5 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | ahmedna126 | NORMAL | 2023-10-24T19:54:25.107254+00:00 | 2023-11-07T11:30:30.517847+00:00 | 2,551 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 23 | 0 | ['Hash Table', 'Java'] | 2 |
first-unique-character-in-a-string | Easy C++ Solution, beats 97% | easy-c-solution-beats-97-by-pooja0406-vqqy | Runtime: 32 ms, faster than 97.50% of C++ online submissions for First Unique Character in a String.\nMemory Usage: 12.6 MB, less than 100.00% of C++ online sub | pooja0406 | NORMAL | 2019-09-11T09:04:54.573381+00:00 | 2019-09-11T09:04:54.573416+00:00 | 3,766 | false | Runtime: 32 ms, faster than 97.50% of C++ online submissions for First Unique Character in a String.\nMemory Usage: 12.6 MB, less than 100.00% of C++ online submissions for First Unique Character in a String.\n\n```\nint firstUniqChar(string s) {\n \n int count[26] = {0};\n for(int i = 0; i<s.length();... | 23 | 2 | ['C'] | 4 |
first-unique-character-in-a-string | Java solution 1ms beats 100% | java-solution-1ms-beats-100-by-sameer_sa-k0q6 | \nclass Solution {\n\t\tpublic int firstUniqChar(String s) {\n int ans = Integer.MAX_VALUE;\n for (char i = \'a\'; i <= \'z\';i++) {\n | Sameer_Saraswat | NORMAL | 2021-12-16T16:19:02.967254+00:00 | 2021-12-16T16:27:21.973979+00:00 | 3,108 | false | ```\nclass Solution {\n\t\tpublic int firstUniqChar(String s) {\n int ans = Integer.MAX_VALUE;\n for (char i = \'a\'; i <= \'z\';i++) {\n int ind = s.indexOf (i);\n if (ind != -1 && ind == s.lastIndexOf (i))\n ans = Math.min (ans,ind);\n }\n if (ans == In... | 21 | 1 | ['Java'] | 2 |
first-unique-character-in-a-string | ✔️Python🔥99% Unique & Fastest solution | Detailed Explanation | Easy understand | beginner-friendly | python99-unique-fastest-solution-detaile-7ddx | Please UPVOTE if you LIKE !!\n\nSuper fast solution:\n Instead of counting every character, we use find() & rfind() to find the first and the last index of that | luluboy168 | NORMAL | 2022-08-16T11:30:26.100903+00:00 | 2022-08-16T11:36:34.142434+00:00 | 3,015 | false | **Please UPVOTE if you LIKE !!**\n\nSuper fast solution:\n* Instead of counting every character, we use `find()` & `rfind()` to find the first and the last index of that character.\n* If both index is the same, it means that the character only appears once.\n* Store the smallest index we found, because it\'s the answer... | 20 | 0 | ['Python'] | 6 |
first-unique-character-in-a-string | CPP || Hashmaps || | cpp-hashmaps-by-akanshapanchal21-u51z | \n#include<unordered_map>\nclass Solution {\npublic:\n int firstUniqChar(string s) {\n unordered_map<char,int> map;\n for(int i=0; i<s.length() | akanshapanchal21 | NORMAL | 2021-03-24T07:01:22.296653+00:00 | 2021-03-24T07:01:22.296694+00:00 | 2,650 | false | ```\n#include<unordered_map>\nclass Solution {\npublic:\n int firstUniqChar(string s) {\n unordered_map<char,int> map;\n for(int i=0; i<s.length(); i++){\n if(map.count(s[i])==0)\n map[s[i]] = 1;\n else\n map[s[i]]++; \n }\n for(int i=... | 20 | 1 | ['C', 'C++'] | 2 |
first-unique-character-in-a-string | C++ 3 simple and easy solutions || concise solutions | c-3-simple-and-easy-solutions-concise-so-wqb9 | please upvote if you find it helpful\n\nclass Solution {\npublic:\n int firstUniqChar(string s)\n {\n unordered_map<char, int> letter;\n con | sailakshmi1 | NORMAL | 2022-08-16T00:03:35.411195+00:00 | 2022-08-16T00:08:19.620705+00:00 | 2,225 | false | **please upvote if you find it helpful**\n```\nclass Solution {\npublic:\n int firstUniqChar(string s)\n {\n unordered_map<char, int> letter;\n const int sSize = s.size();\n for (int i = 0; i < sSize; ++i)\n ++letter[s[i]];\n\n for (int i = 0; i < sSize; ++i)\n if... | 18 | 0 | ['C', 'C++'] | 2 |
first-unique-character-in-a-string | 🗓️ Daily LeetCoding Challenge August, Day 16 | daily-leetcoding-challenge-august-day-16-oewi | This problem is the Daily LeetCoding Challenge for August, Day 16. Feel free to share anything related to this problem here! You can ask questions, discuss what | leetcode | OFFICIAL | 2022-08-16T00:00:24.739813+00:00 | 2022-08-16T00:00:24.739879+00:00 | 5,686 | false | This problem is the Daily LeetCoding Challenge for August, Day 16.
Feel free to share anything related to this problem here!
You can ask questions, discuss what you've learned from this problem, or show off how many days of streak you've made!
---
If you'd like to share a detailed solution to the problem, please cr... | 18 | 0 | [] | 93 |
first-unique-character-in-a-string | my C++ 6 lines Solution | my-c-6-lines-solution-by-iamxiaobai-aisk | \nclass Solution {\npublic:\n int firstUniqChar(string s) {\n int list[256] = {0};\n for(auto i: s)\n list[i] ++;\n for(int i | IamXiaoBai | NORMAL | 2016-11-06T22:36:46.610000+00:00 | 2016-11-06T22:36:46.610000+00:00 | 7,171 | false | ```\nclass Solution {\npublic:\n int firstUniqChar(string s) {\n int list[256] = {0};\n for(auto i: s)\n list[i] ++;\n for(int i=0; i<s.length();i++)\n if(list[s[i]]==1) return i;\n return -1;\n }\n};\n``` | 18 | 0 | [] | 9 |
first-unique-character-in-a-string | ≅ 100% Time & Space | O(N) + O(26) | Mark the ones visited only once as negative! | 100-time-space-on-o26-mark-the-ones-visi-symb | Intuition\n- If an element is visited for the first time, store the position as negative value. Else, if the value had already been visited, store the positive | astrixsanath14 | NORMAL | 2024-02-05T01:21:08.427393+00:00 | 2024-02-05T15:38:34.607296+00:00 | 4,275 | false | # Intuition\n- If an element is visited for the first time, store the position as negative value. Else, if the value had already been visited, store the positive position value. \n- Of all 26 characters, most absolute min value of negative position is the first character!\n\nPS: I didn\'t find any other post with this ... | 17 | 0 | ['C++'] | 4 |
first-unique-character-in-a-string | 99.56% of JavaScript online submissions ,EASY JS SOLUTION | 9956-of-javascript-online-submissions-ea-n07e | \nvar firstUniqChar = function(s) {\n for(let i=0;i<s.length;i++){\n let ch=s[i]\n if(s.indexOf(ch)==i && s.indexOf(ch,i+1)==-1){\n | sftengnr786 | NORMAL | 2021-03-28T13:12:24.657434+00:00 | 2021-03-28T13:12:24.657476+00:00 | 1,962 | false | ```\nvar firstUniqChar = function(s) {\n for(let i=0;i<s.length;i++){\n let ch=s[i]\n if(s.indexOf(ch)==i && s.indexOf(ch,i+1)==-1){\n return i\n }\n }\n return -1\n};\n``` | 17 | 2 | ['JavaScript'] | 6 |
first-unique-character-in-a-string | Python Dictionary, collections.Counter and count 3 ways | python-dictionary-collectionscounter-and-bpc7 | \nclass Solution(object):\n def firstUniqChar(self, s):\n """\n :type s: str\n :rtype: int\n """\n\n for i in range(len(s) | justinnew | NORMAL | 2017-01-20T18:53:15.032000+00:00 | 2017-01-20T18:53:15.032000+00:00 | 8,125 | false | ```\nclass Solution(object):\n def firstUniqChar(self, s):\n """\n :type s: str\n :rtype: int\n """\n\n for i in range(len(s)):\n c = s[i]\n if s.count(c)==1:\n return i\n\n return -1\n\n def firstUniqChar2(self, s):\n\n from co... | 17 | 0 | [] | 5 |
first-unique-character-in-a-string | Freq Count Array vs 2D array||4ms Beats 99.97% | freq-count-array-vs-2d-array4ms-beats-99-0m6q | Intuition\n Describe your first thoughts on how to solve this problem. \nThere are at most 26 alphabets, use an array for freq counting.\n\nLater try other appr | anwendeng | NORMAL | 2024-02-05T01:04:30.704430+00:00 | 2024-02-05T04:33:03.687797+00:00 | 1,682 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThere are at most 26 alphabets, use an array for `freq` counting.\n\nLater try other approach\n\n2nd approach uses 2D array. That records the info\n`freq: alphabet->(last occurrence index, count)`\nThe 2nd loop takes at most $O(26)$ time.... | 16 | 0 | ['Array', 'C++', 'Python3'] | 4 |
first-unique-character-in-a-string | JAVA || 100 % FASTER || 3 LINE HASHMAP CODE | java-100-faster-3-line-hashmap-code-by-s-d7vl | PLEASE UPVOTE IF YOU LIKE IT;\n\n# Code\n\nclass Solution {\n public int firstUniqChar(String s) {\n HashMap<Character, Integer> map = new HashMap<>() | sharforaz_rahman | NORMAL | 2023-03-29T15:33:33.177732+00:00 | 2023-03-29T15:33:33.177768+00:00 | 5,127 | false | **PLEASE UPVOTE IF YOU LIKE IT;**\n\n# Code\n```\nclass Solution {\n public int firstUniqChar(String s) {\n HashMap<Character, Integer> map = new HashMap<>();\n for (char c : s.toCharArray()) map.put(c, map.getOrDefault(c, 0) + 1);\n\n for(int i = 0; i < s.length(); i++){\n if(map.con... | 16 | 0 | ['Hash Table', 'Counting', 'Hash Function', 'Java'] | 4 |
first-unique-character-in-a-string | 2 Method's |🧑💻 BEGINNER FREINDLY|🌟Visualization|JAVA|C++|Python | 2-methods-beginner-freindlyjavacpython-b-jfqs | ✅ IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE AT THE END😊 ✅ :Approach 1: frequency counting approach using a hash map1 . Convert string s to char array st.
2 . Use | Varma5247 | NORMAL | 2025-03-10T11:51:20.896275+00:00 | 2025-03-11T18:20:19.930401+00:00 | 2,747 | false |
✅ **IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE AT THE END**😊 ✅ :
# Approach 1: frequency counting approach using a hash map
<!-- Describe your approach to solving the problem. -->
1 . Convert string ```s``` to char array ```st```.
2 . Use a ```HashMap``` ```map``` to store character frequencies.
3 . Populate ```map``` ... | 15 | 0 | ['Hash Table', 'String', 'Counting', 'Python', 'C++', 'Java', 'Python3'] | 1 |
first-unique-character-in-a-string | ✅✅#2 Methods || Easy & Clean Code ✅✅ | 2-methods-easy-clean-code-by-prikarshglo-248b | Idea:\nAs we need to return first unique character in the string.\nSo we need to store character and its frequency.\n\n# Complexity\n- Time complexity: O(s.size | prikarshglory | NORMAL | 2023-07-17T16:15:30.945068+00:00 | 2023-07-17T16:15:30.945093+00:00 | 1,823 | false | # Idea:\nAs we need to return first unique character in the string.\nSo we need to store character and its frequency.\n\n# Complexity\n- Time complexity: O(s.size())\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(s.size()) -> in queue\n<!-- Add your space complexity here, e.g. $$O(n)$$ ... | 15 | 0 | ['Hash Table', 'String', 'Queue', 'Counting', 'C++'] | 0 |
first-unique-character-in-a-string | Easy C++ Solution | Basic Approach | Array & Loop | easy-c-solution-basic-approach-array-loo-52w6 | Intuition\nJust find the first character whose count is 1 by iterating.\n\n# Approach\nInitialised an array of 26 length to store count of alphabets.\nThen just | HariBhakt | NORMAL | 2022-12-31T17:35:17.423082+00:00 | 2022-12-31T17:35:17.423137+00:00 | 3,726 | false | # Intuition\nJust find the first character whose count is 1 by iterating.\n\n# Approach\nInitialised an array of 26 length to store count of alphabets.\nThen just iterated through the string to find 1st unique character.\n\n# Complexity\n- Time complexity: $$O(n)$$\n\n- Space complexity: $$O(n)$$\n\n# Code\n```\nclass ... | 15 | 0 | ['Array', 'String', 'C++'] | 0 |
first-unique-character-in-a-string | C++ | Brute Force Approach | Efficient Approach | Easy to Understand | c-brute-force-approach-efficient-approac-07mz | Brute Force Approach - O(n^2) time complexity + 2 traversals needed \nFaster than 59.75% of cpp submissions\n\nclass Solution {\npublic:\n int firstUniqChar | manaskarlekar4 | NORMAL | 2021-06-19T06:28:24.117007+00:00 | 2021-06-19T19:05:24.433446+00:00 | 1,477 | false | * **Brute Force Approach** - O(n^2) time complexity + 2 traversals needed \nFaster than 59.75% of cpp submissions\n```\nclass Solution {\npublic:\n int firstUniqChar(string s) \n { \n for(int i=0;i<s.length();i++)\n {\n bool flag = true;\n for(int j=0;j<s.length();j++)\n ... | 14 | 0 | ['C', 'C++'] | 1 |
first-unique-character-in-a-string | 👏🏻 Python | Two Pass & One Pass - 公瑾™ | python-two-pass-one-pass-gong-jin-tm-by-fhi5p | 387. First Unique Character in a String\n\n\n#### Two Pass \n\n> \u7C7B\u578B\uFF1AHash Table\n> Time Complexity O(2N)\n> Space Complexity O(N)\n\n\n\u626B\u4E2 | yuzhoujr | NORMAL | 2018-09-05T05:17:06.694468+00:00 | 2018-09-05T05:17:06.694516+00:00 | 2,874 | false | ### 387. First Unique Character in a String\n\n\n#### Two Pass \n```\n> \u7C7B\u578B\uFF1AHash Table\n> Time Complexity O(2N)\n> Space Complexity O(N)\n```\n\n\u626B\u4E24\u8FB9\uFF0C\u7B2C\u4E00\u904D\u5B58\u5B57\u5178\uFF0C\u7B2C\u4E8C\u904D\u67E5\u627E\uFF0C\u5982\u679C\u5B57\u5178\u91CC\u9762\u5BF9\u5E94Counter\u4E... | 14 | 2 | [] | 5 |
first-unique-character-in-a-string | Python || 3 diff way || 99% beats | python-3-diff-way-99-beats-by-vvivekyada-c82v | If you got help from this,... Plz Upvote .. it encourage me\n# Code\n> # HashMap\n\n# HASHMAP\nclass Solution:\n def firstUniqChar(self, s: str) -> int:\n | vvivekyadav | NORMAL | 2023-10-09T12:39:54.372893+00:00 | 2023-10-09T12:39:54.372983+00:00 | 1,225 | false | **If you got help from this,... Plz Upvote .. it encourage me**\n# Code\n> # HashMap\n```\n# HASHMAP\nclass Solution:\n def firstUniqChar(self, s: str) -> int:\n d = {}\n for char in s:\n d[char] = d.get(char,0) + 1\n \n for i , char in enumerate(s):\n if d[char] == ... | 13 | 0 | ['Hash Table', 'String', 'Counting', 'Python', 'Python3'] | 1 |
first-unique-character-in-a-string | OnlyCode in JAVA using HashMap ✅ || | onlycode-in-java-using-hashmap-by-saksha-y30t | \n\n# Code\n\nclass Solution {\n public int firstUniqChar(String str) {\n HashMap<Character,Integer> map = new HashMap<>();\n for(int i=0;i<str | sakshamkaushiik | NORMAL | 2023-02-03T19:10:25.247305+00:00 | 2023-02-03T19:10:25.247345+00:00 | 3,152 | false | \n\n# Code\n```\nclass Solution {\n public int firstUniqChar(String str) {\n HashMap<Character,Integer> map = new HashMap<>();\n for(int i=0;i<str.length();i++){\n if(map.containsKey(str.charAt(i))){\n map.put(str.charAt(i),map.get(str.charAt(i))+1);\n }else{\n ... | 13 | 0 | ['Hash Table', 'Java'] | 2 |
first-unique-character-in-a-string | ✅C beats 100%🔥| Easy to understand | beginner-friendly ^_^ | c-beats-100-easy-to-understand-beginner-j0z6v | \nint firstUniqChar(char * s){\n int i = 0, map[26], sSize = strlen(s);\n \n for(i; i < 26; i++)\n map[i] = 0;\n \n for(i=0; i < sSize; i+ | luluboy168 | NORMAL | 2022-08-16T11:54:33.147318+00:00 | 2022-08-16T11:54:33.147362+00:00 | 1,056 | false | ```\nint firstUniqChar(char * s){\n int i = 0, map[26], sSize = strlen(s);\n \n for(i; i < 26; i++)\n map[i] = 0;\n \n for(i=0; i < sSize; i++)\n map[s[i] - \'a\']++;\n \n for(i=0; i < sSize; i++)\n if (map[s[i] - \'a\'] == 1)\n return i;\n \n return -1;\n}\n``... | 13 | 0 | ['C'] | 2 |
first-unique-character-in-a-string | PYTHON SIMPLE SOLUTION | python-simple-solution-by-coder_hash-0l4t | Input: "loveleetcode"\nOutput: 2\n\nAt position 2, if we see [lo]+[eleetcode], there is no occurance of \'v\',\nSo we return 2\n\nFor loop is finished and still | coder_hash | NORMAL | 2022-02-01T12:19:58.702966+00:00 | 2022-02-01T12:20:36.190995+00:00 | 546 | false | Input: "loveleetcode"\nOutput: 2\n\nAt position 2, if we see [lo]+[eleetcode], there is no occurance of \'v\',\nSo we return 2\n\nFor loop is finished and still nothing is returned, we return -1\n```\nclass Solution(object):\n def firstUniqChar(self, s):\n for i in range(len(s)):\n if s[i] not in s... | 13 | 0 | ['Python'] | 0 |
first-unique-character-in-a-string | Swift: First Unique Character in a String (✅ Test Cases) | swift-first-unique-character-in-a-string-1cob | swift\nclass Solution {\n func firstUniqChar(_ s: String) -> Int {\n var arr = Array(repeating: 0, count: 26)\n let a = UnicodeScalar("a").valu | AsahiOcean | NORMAL | 2021-07-09T05:36:01.397284+00:00 | 2021-07-09T05:36:01.397341+00:00 | 1,550 | false | ```swift\nclass Solution {\n func firstUniqChar(_ s: String) -> Int {\n var arr = Array(repeating: 0, count: 26)\n let a = UnicodeScalar("a").value\n s.unicodeScalars.forEach{\n arr[Int($0.value - a)] += 1\n }\n var iter = 0\n for ch in s.unicodeScalars {\n ... | 13 | 1 | ['Swift'] | 0 |
first-unique-character-in-a-string | Easy Python Solution | easy-python-solution-by-aadit-wcfv | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | aadit_ | NORMAL | 2025-02-07T09:18:28.929807+00:00 | 2025-02-07T09:18:28.929807+00:00 | 1,299 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 12 | 0 | ['Python3'] | 0 |
first-unique-character-in-a-string | ✅Accepted| | ✅Easy solution || ✅Short & Simple || ✅Best Method | accepted-easy-solution-short-simple-best-k3k4 | \n# Code\n\nclass Solution {\npublic:\n int firstUniqChar(string s) {\n unordered_map<char, int> m;\n for (char& c : s) {\n m[c]++; | sanjaydwk8 | NORMAL | 2023-01-17T06:18:20.087499+00:00 | 2023-01-17T06:18:20.087553+00:00 | 2,605 | false | \n# Code\n```\nclass Solution {\npublic:\n int firstUniqChar(string s) {\n unordered_map<char, int> m;\n for (char& c : s) {\n m[c]++;\n }\n for (int i = 0; i < s.size(); i++) {\n if (m[s[i]] == 1)\n return i;\n }\n return -1;\n }\n};... | 12 | 0 | ['C++'] | 0 |
first-unique-character-in-a-string | C++ CONSTANT SPACE solution O(1) SPACE VERY FAST!! SICKEST 😷😷😷 | c-constant-space-solution-o1-space-very-dvikv | Keep a frequency map of all characters in s. \nUse a vector of size 26 for speed\nreturn first index that the count is == 1\n\nTime complexity: O(N)\nSpace com | midnightsimon | NORMAL | 2022-08-16T01:17:14.134053+00:00 | 2022-08-16T01:17:29.776335+00:00 | 2,237 | false | Keep a frequency map of all characters in s. \nUse a vector of size 26 for speed\nreturn first index that the count is == 1\n\nTime complexity: O(N)\nSpace complexity: O(1) because its just vector of size 26 everytime\n\n**SOLVED LIVE ON STREAM. link in profile. check out my sick keyboards.**\n```\nclass Solution {\n... | 12 | 2 | [] | 6 |
first-unique-character-in-a-string | My 4 Line, O(N) Solution ! 5ms beats 100% | my-4-line-on-solution-5ms-beats-100-by-l-33vj | \npublic int firstUniqChar(String s) {\n\n int freq[] = new int[26];\n for(char i: s.toCharArray()) freq[i-\'a\']++;\n for(int i = | leetcoderkk | NORMAL | 2021-02-25T13:57:30.471643+00:00 | 2021-02-25T13:57:59.152619+00:00 | 1,983 | false | ```\npublic int firstUniqChar(String s) {\n\n int freq[] = new int[26];\n for(char i: s.toCharArray()) freq[i-\'a\']++;\n for(int i = 0; i < s.length(); i++) if(freq[s.charAt(i)-\'a\'] == 1) return i;\n return -1;\n \n }\n``` | 12 | 0 | ['Java'] | 3 |
first-unique-character-in-a-string | ✅✅✅ easy brute force||Upvote if you like ⬆️⬆️ | easy-brute-forceupvote-if-you-like-by-ra-qi8g | \n\n# Code\n\nclass Solution {\npublic:\n int firstUniqChar(string s) {\n int n=s.size();\n \n \n for(int i=0;i<n;i++)\n { | ratnesh_maurya | NORMAL | 2022-12-04T14:38:12.221630+00:00 | 2022-12-08T19:03:05.277833+00:00 | 1,175 | false | \n\n# Code\n```\nclass Solution {\npublic:\n int firstUniqChar(string s) {\n int n=s.size();\n \n \n for(int i=0;i<n;i++)\n {\n int flag=1;\n for(int j=0;j<n;j++)\n {\n if(i!=j && s[i]==s[j])\n {\n f... | 11 | 0 | ['C++'] | 0 |
first-unique-character-in-a-string | [C++] Array-based Solutions Compared and Explained, ~100% Time, ~90% Space | c-array-based-solutions-compared-and-exp-ptpd | For this problem I decided to go straight for an array approach to build a frequency table of all the seen characters and then iterate again to find the first w | ajna | NORMAL | 2020-12-20T11:02:37.300536+00:00 | 2021-06-19T08:43:43.174370+00:00 | 1,064 | false | For this problem I decided to go straight for an array approach to build a frequency table of all the seen characters and then iterate again to find the first with a frequency of only `1`.\n\nTo do so, I created 2 support variables:\n* `len` to store the length of the string;\n* `alpha`, the aforementioned frequency ta... | 11 | 0 | ['Array', 'C', 'Counting', 'C++'] | 1 |
first-unique-character-in-a-string | Python simple solution 60 ms, faster than 96.16% | python-simple-solution-60-ms-faster-than-cvv9 | \nclass Solution:\n def firstUniqChar(self, s: str) -> int:\n visited = set()\n for i in range(len(s)):\n if s[i] not in visited:\n | hemina | NORMAL | 2020-05-05T21:28:12.073448+00:00 | 2020-05-05T21:28:12.073483+00:00 | 2,283 | false | ```\nclass Solution:\n def firstUniqChar(self, s: str) -> int:\n visited = set()\n for i in range(len(s)):\n if s[i] not in visited:\n visited.add(s[i])\n if s.count(s[i]) == 1:\n return i\n return -1\n``` | 11 | 3 | ['Python', 'Python3'] | 4 |
first-unique-character-in-a-string | JS Solution | js-solution-by-rano3003-j6lt | \n/**\n * @param {string} s\n * @return {number}\n */\nvar firstUniqChar = function(s) {\n for(var i =0 ; i < s.length ; i++) {\n if(s.indexOf(s[i]) = | rano3003 | NORMAL | 2020-05-05T08:00:00.923549+00:00 | 2020-05-05T08:00:00.923605+00:00 | 291 | false | ```\n/**\n * @param {string} s\n * @return {number}\n */\nvar firstUniqChar = function(s) {\n for(var i =0 ; i < s.length ; i++) {\n if(s.indexOf(s[i]) == s.lastIndexOf(s[i])) {\n return i;\n } \n }return -1\n \n};\n``` | 11 | 0 | [] | 0 |
first-unique-character-in-a-string | javascript | beats 98% | O(n) time | O(1) space | javascript-beats-98-on-time-o1-space-by-fn0zs | states is an array of 26 states (represented by an integer) corresponding to each possible character.\nIf a state is -1, the character has not been encountered | functaire | NORMAL | 2016-11-17T11:58:28.043000+00:00 | 2016-11-17T11:58:28.043000+00:00 | 2,229 | false | `states` is an array of 26 states (represented by an integer) corresponding to each possible character.\nIf a state is `-1`, the character has not been encountered yet.\nIf a state is `-2`, the character has been encountered more than once.\nOtherwise, the state represents the index at which the character was first enc... | 11 | 1 | [] | 2 |
first-unique-character-in-a-string | The Efficient First Unique Character Finder | [C++, Java, Python] | O(n) | the-efficient-first-unique-character-fin-sdj3 | Intuition:\nUtilize a fixed-size array to efficiently count the occurrences of each character in the given string.\n\n# Approach:\n1. Initialize a list of size | kartikeylapy | NORMAL | 2024-02-05T08:43:17.782339+00:00 | 2024-02-05T08:43:17.782373+00:00 | 746 | false | # Intuition:\nUtilize a fixed-size array to efficiently count the occurrences of each character in the given string.\n\n# Approach:\n1. Initialize a list of size 26 to represent the occurrences of each letter.\n2. Iterate through the string to count the occurrences of each character.\n3. Traverse the string again and r... | 10 | 0 | ['String', 'Python', 'Java'] | 0 |
first-unique-character-in-a-string | Easy to Understand Java Solution using HashMap | easy-to-understand-java-solution-using-h-qwlc | \nclass Solution {\n public int firstUniqChar(String s) {\n HashMap<Character,Integer> map = new HashMap<>();//Creating a hashmap which will take aver | Abhinav_0561 | NORMAL | 2022-10-10T03:39:09.700788+00:00 | 2022-10-10T03:39:09.700864+00:00 | 1,421 | false | ```\nclass Solution {\n public int firstUniqChar(String s) {\n HashMap<Character,Integer> map = new HashMap<>();//Creating a hashmap which will take avery character and note its occurrence.\n for(int i = 0 ; i < s.length() ; i++){\n map.put(s.charAt(i), map.getOrDefault(s.charAt(i),0)+1);\n ... | 10 | 0 | ['Java'] | 0 |
first-unique-character-in-a-string | [Go] O(n) Hashmap with explanation | go-on-hashmap-with-explanation-by-maxyzl-wrbw | go\nfunc firstUniqChar(s string) int {\n\td := map[byte]int{}\n\n\t// Count each character.\n\tfor i := 0; i < len(s); i++ {\n\t\td[s[i]]++\n\t}\n\n\t// Find th | maxyzli | NORMAL | 2019-07-18T08:17:05.474115+00:00 | 2019-07-18T08:18:03.619879+00:00 | 573 | false | ```go\nfunc firstUniqChar(s string) int {\n\td := map[byte]int{}\n\n\t// Count each character.\n\tfor i := 0; i < len(s); i++ {\n\t\td[s[i]]++\n\t}\n\n\t// Find the first unique character and return.\n\tfor i := 0; i < len(s); i++ {\n\t\tif d[s[i]] == 1 {\n\t\t\treturn i\n\t\t}\n\t}\n\n\t// If there\'s no unique charac... | 10 | 0 | ['Go'] | 1 |
first-unique-character-in-a-string | Clean Python Solution | clean-python-solution-by-christopherwu05-bdl9 | python\nfrom collections import Counter\n\nclass Solution(object):\n def firstUniqChar(self, string):\n # counter = Counter()\n # for char in s | christopherwu0529 | NORMAL | 2019-03-20T06:18:14.538597+00:00 | 2019-09-20T01:53:04.113017+00:00 | 2,061 | false | ```python\nfrom collections import Counter\n\nclass Solution(object):\n def firstUniqChar(self, string):\n # counter = Counter()\n # for char in string:\n # counter[char]+=1\n counter = Counter(string)\n\n for i in xrange(len(string)):\n char = string[i]\n ... | 10 | 0 | [] | 2 |
first-unique-character-in-a-string | Simple Solution, Single Pass | simple-solution-single-pass-by-fabrizio3-tuiq | \npublic int firstUniqChar(String s) {\n\tif(s==null || s.length()==0) {\n\t\treturn -1;\n\t}\n\tchar[] chars = s.toCharArray();\n\tMap<Character,Integer> chars | fabrizio3 | NORMAL | 2016-08-22T10:25:04.498000+00:00 | 2016-08-22T10:25:04.498000+00:00 | 6,141 | false | ```\npublic int firstUniqChar(String s) {\n\tif(s==null || s.length()==0) {\n\t\treturn -1;\n\t}\n\tchar[] chars = s.toCharArray();\n\tMap<Character,Integer> charsPositions = new HashMap<>();\n\tList<Integer> uniqsPositions = new ArrayList<>();\n\tfor(int i=0; i<chars.length; i++) {\n\t\tchar c = chars[i];\n\t\tif(char... | 10 | 3 | ['Java'] | 5 |
first-unique-character-in-a-string | TRUE O(1) extra memory with only two integers!!! using bits | true-o1-extra-memory-with-only-two-integ-r99a | Intuition\n Describe your first thoughts on how to solve this problem. \ni had initially thought about using map or array[26], or string ,ect...but then, we don | abhiram542 | NORMAL | 2024-02-06T19:08:15.785571+00:00 | 2024-02-07T09:19:33.748097+00:00 | 147 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\ni had initially thought about using map or array[26], or string ,ect...but then, we don\'t need exact frequency of each character. we need to know which of the following three states each character will be\n - 1) unvisited \n - 2) visit... | 9 | 0 | ['Bit Manipulation', 'Counting', 'Bitmask', 'C++'] | 3 |
first-unique-character-in-a-string | 🔥2 and 4 lines of code both suitable approach✅|| Easy to understand|| Beat 96% time and 97% space🚀 | 2-and-4-lines-of-code-both-suitable-appr-4exk | Intuition\n# Python and Python3 :\n1. \'for i in range(len(s)):\' : This line initiates a for loop that iterates over the indices of the characters in the strin | siddharth-kiet | NORMAL | 2024-02-05T06:03:50.825997+00:00 | 2024-02-13T19:27:40.878657+00:00 | 630 | false | # Intuition\n# **Python and Python3 :**\n1. **\'for i in range(len(s)):\' :** This line initiates a for loop that iterates over the indices of the characters in the string s. The loop variable i represents the current index.\n2. **\'if s.count(s[i]) == 1:\' :** Within the loop, it checks if the count of the current cha... | 9 | 0 | ['Hash Table', 'String', 'Queue', 'Counting', 'Python', 'C++', 'Python3'] | 0 |
first-unique-character-in-a-string | Hash map solution ,C++ better and easy solution | hash-map-solution-c-better-and-easy-solu-1kqf | \nint firstUniqChar(string s) \n {\n unordered_map<char,int> map;\n for(int i=0; i<s.length(); i++)\n {\n map[s[i]]++; | vchand324 | NORMAL | 2021-06-19T17:16:59.140767+00:00 | 2021-06-19T17:16:59.140796+00:00 | 795 | false | ```\nint firstUniqChar(string s) \n {\n unordered_map<char,int> map;\n for(int i=0; i<s.length(); i++)\n {\n map[s[i]]++; \n }\n for(int i=0; i<s.length(); i++)\n { \n if(map[s[i]] == 1)\n return i;\n }\n return -1;\n... | 9 | 0 | ['C'] | 5 |
first-unique-character-in-a-string | Intuitive Javascript Solution | intuitive-javascript-solution-by-ishiima-3j66 | Runtime: 108 ms, faster than 81.91% of JavaScript online submissions for First Unique Character in a String.\nMemory Usage: 42.5 MB, less than 50.33% of JavaScr | ishiimatthew | NORMAL | 2021-01-06T00:08:14.329266+00:00 | 2021-01-06T00:08:29.168413+00:00 | 696 | false | Runtime: 108 ms, faster than 81.91% of JavaScript online submissions for First Unique Character in a String.\nMemory Usage: 42.5 MB, less than 50.33% of JavaScript online submissions for First Unique Character in a String.\n```\n\nvar firstUniqChar = function(s) {\n for(let i = 0; i < s.length; i++) {\n\t\t// Here w... | 9 | 0 | [] | 2 |
first-unique-character-in-a-string | C# charAndCount | c-charandcount-by-bacon-is4w | \npublic class Solution {\n public int FirstUniqChar(string s) {\n var charAndCount = new int[256];\n\n foreach (var c in s) {\n cha | bacon | NORMAL | 2019-06-23T20:36:44.040901+00:00 | 2019-06-23T20:36:44.040956+00:00 | 1,252 | false | ```\npublic class Solution {\n public int FirstUniqChar(string s) {\n var charAndCount = new int[256];\n\n foreach (var c in s) {\n charAndCount[c]++;\n }\n\n for (int i = 0; i < s.Length; i++) {\n if (charAndCount[s[i]] == 1) {\n return i;\n ... | 9 | 0 | [] | 2 |
first-unique-character-in-a-string | C# Linq Count Method | c-linq-count-method-by-xenoplastic-mb6d | here C# solution, using Count Method\n\npublic class Solution {\n public int FirstUniqChar(string s) {\n foreach(var itm in s.Distinct()){\n | xenoplastic | NORMAL | 2019-02-05T00:12:53.589545+00:00 | 2019-02-05T00:12:53.589585+00:00 | 931 | false | here C# solution, using Count Method\n```\npublic class Solution {\n public int FirstUniqChar(string s) {\n foreach(var itm in s.Distinct()){\n if(s.Count(x=>x==itm)==1){\n return s.IndexOf(itm);\n }\n }\n return -1;\n\n }\n}\n``` | 9 | 0 | [] | 2 |
first-unique-character-in-a-string | Python very easy solution | python-very-easy-solution-by-hayek-wdj8 | \nclass Solution(object):\n def firstUniqChar(self, str1):\n """\n :type s: str\n :rtype: int\n """\n for x in str1:\n | hayek | NORMAL | 2016-08-22T07:50:44.635000+00:00 | 2016-08-22T07:50:44.635000+00:00 | 4,407 | false | ```\nclass Solution(object):\n def firstUniqChar(self, str1):\n """\n :type s: str\n :rtype: int\n """\n for x in str1:\n if str1.find(x)==str1.rfind(x):\n return str1.find(x)\n return -1\n``` | 9 | 2 | [] | 3 |
first-unique-character-in-a-string | Golang concise solution | golang-concise-solution-by-redtree1112-h0qu | The idea is simple.\n\n1. Create a flag array that holds flags for each [a-z] characters and initialize all indexes with -1.\n2. Iterate through s and if a char | redtree1112 | NORMAL | 2017-02-14T10:43:40.726000+00:00 | 2017-02-14T10:43:40.726000+00:00 | 1,049 | false | The idea is simple.\n\n1. Create a flag array that holds flags for each [a-z] characters and initialize all indexes with `-1`.\n2. Iterate through `s` and if a character appears, set the index to the flag array. If the character appears again,\n we can set invalid index to the flag. I use `len(s)` in the code below.... | 9 | 0 | ['Go'] | 3 |
first-unique-character-in-a-string | Java || Easy to Understand ❤️❤️ || Queue || 0(N) || 2 Solutions || ❤️❤️ | java-easy-to-understand-queue-0n-2-solut-hryq | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | saurabh_kumar1 | NORMAL | 2023-09-11T07:44:11.045847+00:00 | 2023-09-11T07:44:11.045868+00:00 | 1,567 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:0(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:0(1)\n<!-- Add your space complexity here, e.g. $$O... | 8 | 0 | ['String', 'Queue', 'Java'] | 2 |
first-unique-character-in-a-string | ✅Short || C++ || Java || PYTHON || Explained Solution✔️ || Beginner Friendly ||🔥 🔥 BY MR CODER | short-c-java-python-explained-solution-b-7zyv | Please UPVOTE if you LIKE!!\nWatch this video \uD83E\uDC83 for the better explanation of the code.\n\nhttps://www.youtube.com/watch?v=HVmq6apu3Zk\n\n\nAlso you | mrcoderrm | NORMAL | 2022-09-12T19:06:16.992444+00:00 | 2022-09-12T19:06:16.992491+00:00 | 1,467 | false | **Please UPVOTE if you LIKE!!**\n**Watch this video \uD83E\uDC83 for the better explanation of the code.**\n\nhttps://www.youtube.com/watch?v=HVmq6apu3Zk\n\n\n**Also you can SUBSCRIBE \uD83E\uDC81 \uD83E\uDC81 \uD83E\uDC81 this channel for the daily leetcode challange solution.**\n\n\n**C++**\n```\nclass Solution {\np... | 8 | 0 | ['C', 'Python', 'C++', 'Java'] | 0 |
first-unique-character-in-a-string | Kotlin 1 line | kotlin-1-line-by-georgcantor-ep23 | \nfun firstUniqChar(s: String) = s.indexOfFirst { s.indexOf(it) == s.lastIndexOf(it) }\n | GeorgCantor | NORMAL | 2021-12-26T19:08:57.835133+00:00 | 2021-12-26T19:08:57.835184+00:00 | 470 | false | ```\nfun firstUniqChar(s: String) = s.indexOfFirst { s.indexOf(it) == s.lastIndexOf(it) }\n``` | 8 | 0 | ['Kotlin'] | 1 |
first-unique-character-in-a-string | Map() in JavaScript | map-in-javascript-by-danielyu74-zxtt | \nvar firstUniqChar = function(s) {\n const count = new Map();\n for(let i = 0; i < s.length; i++) {\n if(!count[s[i]]) {\n count[s[i]] | danielyu74 | NORMAL | 2021-01-15T23:34:22.331108+00:00 | 2021-01-15T23:37:36.303133+00:00 | 1,124 | false | ```\nvar firstUniqChar = function(s) {\n const count = new Map();\n for(let i = 0; i < s.length; i++) {\n if(!count[s[i]]) {\n count[s[i]] = 1;\n } else {\n count[s[i]]++\n }\n }\n for(let i = 0; i < s.length; i++) {\n if(count[s[i]] === 1) return i\n } ... | 8 | 3 | ['JavaScript'] | 3 |
first-unique-character-in-a-string | very easy solution with explanation c++| java | python | javascript | very-easy-solution-with-explanation-c-ja-sig8 | Intuition\nThe intuition behind this solution is to use an unordered map (M) to store the frequency of each character in the input string (s). The first loop it | prashant_71200 | NORMAL | 2024-02-05T03:36:22.819517+00:00 | 2024-02-05T03:37:58.206344+00:00 | 974 | false | # Intuition\nThe intuition behind this solution is to use an unordered map (M) to store the frequency of each character in the input string (s). The first loop iterates through the string and populates the map with the count of each character. The second loop then checks the frequency of each character in the map and r... | 7 | 0 | ['Python', 'C++', 'Java', 'JavaScript'] | 0 |
first-unique-character-in-a-string | Short and Easy | Using Counter | Python | short-and-easy-using-counter-python-by-p-1045 | Complexity\n- Time complexity:O(n)\n\n- Space complexity:O(n)\n\n# Code\n\nclass Solution:\n def firstUniqChar(self, s: str) -> int:\n count = Counter | pragya_2305 | NORMAL | 2024-02-05T02:12:03.915793+00:00 | 2024-02-05T02:12:03.915873+00:00 | 1,316 | false | # Complexity\n- Time complexity:O(n)\n\n- Space complexity:O(n)\n\n# Code\n```\nclass Solution:\n def firstUniqChar(self, s: str) -> int:\n count = Counter(s)\n\n for i,c in enumerate(s):\n if count[c]==1:\n return i\n\n return -1\n``` | 7 | 0 | ['Hash Table', 'Python', 'Python3'] | 0 |
first-unique-character-in-a-string | Easy to understand || C++ | easy-to-understand-c-by-yashwardhan24_sh-rkxn | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | yashwardhan24_sharma | NORMAL | 2023-03-28T05:15:29.979825+00:00 | 2023-03-28T05:15:29.979869+00:00 | 2,169 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 7 | 0 | ['Hash Table', 'C++'] | 0 |
first-unique-character-in-a-string | C++ ✔|| Constant Spaces o(1) || O(N) Time complexity ✅ | c-constant-spaces-o1-on-time-complexity-ic3il | \nclass Solution {\npublic:\n int firstUniqChar(string s) {\n int n=s.size();\n vector<int> m(26,0);\n for(char a : s){\n m[ | Ayuk_05 | NORMAL | 2022-08-16T05:09:15.948348+00:00 | 2022-08-16T05:09:15.948391+00:00 | 690 | false | ```\nclass Solution {\npublic:\n int firstUniqChar(string s) {\n int n=s.size();\n vector<int> m(26,0);\n for(char a : s){\n m[a-\'a\']++;\n }\n int ans=-1;\n for(int i=0;i<n;++i){\n if(m[s[i]-\'a\']==1){\n ans=i;\n break;... | 7 | 2 | ['C'] | 0 |
first-unique-character-in-a-string | Easy Python Solution | easy-python-solution-by-vistrit-rj7p | \ndef firstUniqChar(self, s: str) -> int:\n c=Counter(s)\n for i,j in enumerate(s):\n if c[j]<=1:\n return i\n re | vistrit | NORMAL | 2021-12-06T04:39:24.734991+00:00 | 2021-12-06T04:39:24.735030+00:00 | 1,172 | false | ```\ndef firstUniqChar(self, s: str) -> int:\n c=Counter(s)\n for i,j in enumerate(s):\n if c[j]<=1:\n return i\n return -1\n``` | 7 | 0 | ['Python', 'Python3'] | 0 |
first-unique-character-in-a-string | Java Queue Solution | java-queue-solution-by-aatmik_coder-7c28 | ```\nclass Solution {\n public int firstUniqChar(String s) {\n Queue ch = new LinkedList();\n int len = s.length();\n char temper = 0;\n | Aatmik_Coder | NORMAL | 2021-11-09T06:05:44.096905+00:00 | 2021-11-09T06:05:44.096947+00:00 | 1,551 | false | ```\nclass Solution {\n public int firstUniqChar(String s) {\n Queue<Character> ch = new LinkedList<Character>();\n int len = s.length();\n char temper = 0;\n for(int j = 0; j < s.length(); j++)\n {\n ch.offer(s.charAt(j));\n }\n while(len > 0)\n {\n... | 7 | 1 | ['Queue', 'Java'] | 0 |
first-unique-character-in-a-string | C simple code | c-simple-code-by-bindhushreehr-qlyh | \nint firstUniqChar(char * s){\n int alph[26]={0};\n \n if (s==NULL)\n return -1;\n \n for (int i=0;s[i]!=\'\\0\';i++)\n {\n alp | bindhushreehr | NORMAL | 2020-08-28T14:25:17.390204+00:00 | 2020-08-28T14:26:00.632599+00:00 | 720 | false | ```\nint firstUniqChar(char * s){\n int alph[26]={0};\n \n if (s==NULL)\n return -1;\n \n for (int i=0;s[i]!=\'\\0\';i++)\n {\n alph[s[i] - \'a\'] = alph[s[i] - \'a\']+1;\n }\n \n for(int i=0;s[i]!=\'\\0\';i++)\n {\n if (1 == alph[s[i] - \'a\'])\n return i;\... | 7 | 0 | ['Hash Table', 'C'] | 0 |
first-unique-character-in-a-string | Python | Single Pass Using Queue | python-single-pass-using-queue-by-ared25-a2wk | \nfrom collections import deque\nclass Solution:\n def firstUniqChar(self, s: str) -> int:\n d = {}\n q = deque()\n for i, x in enumerat | ared25 | NORMAL | 2020-02-27T14:41:56.994940+00:00 | 2020-02-27T14:45:04.783352+00:00 | 1,021 | false | ```\nfrom collections import deque\nclass Solution:\n def firstUniqChar(self, s: str) -> int:\n d = {}\n q = deque()\n for i, x in enumerate(s):\n d[x] = d.get(x, 0) + 1\n if d[x] == 1:\n q.append((x, i))\n while q and d[q[0][0]] > 1:\n ... | 7 | 0 | ['Python'] | 1 |
first-unique-character-in-a-string | Java using twice scans | java-using-twice-scans-by-sjhuangx-u18c | the first scan we statistics the number of each letter in string.\nthe second scan we find the first letter which number equals 1.\n\npublic class Solution {\n | sjhuangx | NORMAL | 2016-08-22T07:51:25.962000+00:00 | 2016-08-22T07:51:25.962000+00:00 | 2,778 | false | the first scan we statistics the number of each letter in string.\nthe second scan we find the first letter which number equals 1.\n```\npublic class Solution {\n public int firstUniqChar(String s) {\n if (s == null || s.isEmpty()) {\n return -1;\n }\n int[] letters = new int[26];\n ... | 7 | 0 | [] | 2 |
first-unique-character-in-a-string | Simple Java || C++ Codes ☠️ | simple-java-c-codes-by-abhinandannaik171-8bt1 | Bruteforce Code\njava []\nclass Solution {\n public int firstUniqChar(String s) {\n int n = s.length();\n for(int i=0;i<n;i++){\n fo | abhinandannaik1717 | NORMAL | 2024-08-23T17:18:48.920393+00:00 | 2024-08-23T17:18:48.920422+00:00 | 599 | false | # Bruteforce Code\n```java []\nclass Solution {\n public int firstUniqChar(String s) {\n int n = s.length();\n for(int i=0;i<n;i++){\n for(int j=0;j<n;j++){\n if(i==n-1 && j==n-1){\n return i;\n }\n if(i==j){\n ... | 6 | 0 | ['Hash Table', 'String', 'Counting', 'C++', 'Java'] | 0 |
first-unique-character-in-a-string | 387. First Unique Character in a String| SC: O(1) |Bit Manipulation|TC: O(N) | 387-first-unique-character-in-a-string-s-wyem | Intuition\n Describe your first thoughts on how to solve this problem. \nTo find the first single frequency of char in a String is achieved by two interger vari | 21csa36 | NORMAL | 2024-02-05T07:00:48.603211+00:00 | 2024-02-05T07:00:48.603244+00:00 | 200 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTo find the first single frequency of char in a String is achieved by two interger varible (mask1 and mask2) used as mask to store the freq. \n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nSince Integer has 32 bit... | 6 | 0 | ['Bit Manipulation', 'Bitmask', 'Python', 'C++', 'Java', 'Python3'] | 3 |
first-unique-character-in-a-string | 🚀🚀 Beats 100% | Easiest Approach 💎🔥 | beats-100-easiest-approach-by-sanket_des-8ugk | Intuition \uD83E\uDD14:\nWe want to find the first character in the string that doesn\'t repeat. That means we need to count how many times each character appea | The_Eternal_Soul | NORMAL | 2024-02-05T01:52:49.256599+00:00 | 2024-02-05T01:52:49.256626+00:00 | 1,145 | false | **Intuition** \uD83E\uDD14:\nWe want to find the first character in the string that doesn\'t repeat. That means we need to count how many times each character appears in the string.\n\n**Approach** \uD83D\uDCA1:\n1. We\'ll use a map to count the occurrences of each character in the string.\n2. Then, we\'ll iterate thro... | 6 | 1 | ['Hash Table', 'String', 'C', 'Counting', 'Python', 'C++', 'Java', 'JavaScript'] | 0 |
first-unique-character-in-a-string | simple solution for beginners | simple-solution-for-beginners-by-hrishik-nlle | \n\n# Code\n\nclass Solution:\n def firstUniqChar(self, s: str) -> int:\n for i in range(len(s)):\n if s.count(s[i])==1:\n r | hrishikeshprasadc | NORMAL | 2023-12-02T03:31:08.453558+00:00 | 2023-12-02T03:31:08.453635+00:00 | 333 | false | \n\n# Code\n```\nclass Solution:\n def firstUniqChar(self, s: str) -> int:\n for i in range(len(s)):\n if s.count(s[i])==1:\n return i\n return -1\n\n``` | 6 | 0 | ['Python3'] | 0 |
first-unique-character-in-a-string | 387: Space 93.87%, Solution with step by step explanation | 387-space-9387-solution-with-step-by-ste-kg4z | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n1. We define a class Solution with a method firstUniqChar that takes a st | Marlen09 | NORMAL | 2023-03-04T07:02:14.391970+00:00 | 2023-03-04T07:02:14.392015+00:00 | 2,888 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n1. We define a class Solution with a method firstUniqChar that takes a string s as input and returns an integer.\n2. We create an empty dictionary freq to store the frequency of each character in the string.\n3. We iterate t... | 6 | 0 | ['Hash Table', 'String', 'Queue', 'Python', 'Python3'] | 0 |
first-unique-character-in-a-string | Python | Beats 99% | 3 Solutions | O(N) | python-beats-99-3-solutions-on-by-nadara-bdwa | \n\n\n\nThe 3rd solution beats 99%\n\n\n1. We run over s to count how many times each character appears.\n\n2. We run over s again, and whenever we meet a chara | nadaralp | NORMAL | 2022-08-16T08:34:01.272789+00:00 | 2022-08-16T08:46:22.852509+00:00 | 635 | false | \n\n<hr />\n\nThe 3rd solution beats 99%\n<hr />\n\n1. We run over `s` to count how many times each character appears.\n\n2. We run over `s` again, and whenever we meet a character that appears only once, we re... | 6 | 0 | ['Python'] | 0 |
first-unique-character-in-a-string | Java / C++ Map | java-c-map-by-fllght-auer | \n\nAlso added a shorter (and slower) solution using the stream API.\n\n#### Java\n\npublic int firstUniqChar(String s) {\n Map<Character, Integer> chara | FLlGHT | NORMAL | 2022-08-16T04:56:02.296915+00:00 | 2022-08-16T06:25:45.241549+00:00 | 1,055 | false | \n\nAlso added a shorter (and slower) solution using the stream API.\n\n#### Java\n```\npublic int firstUniqChar(String s) {\n Map<Character, Integer> characterMap = new HashMap<>();\n for (char c : s.toCharArray()) {\n characterMap.put(c, characterMap.getOrDefault(c, 0) + 1);\n }\n ... | 6 | 1 | ['C', 'Java'] | 1 |
first-unique-character-in-a-string | JAVA, if u want to practice HashMap | java-if-u-want-to-practice-hashmap-by-sh-qevi | class Solution {\n public int firstUniqChar(String s) {\n HashMap ans = new HashMap <>();\n \n //go through the whole string, record th | shiwenbot | NORMAL | 2022-03-16T11:25:50.005118+00:00 | 2022-03-16T11:25:50.005170+00:00 | 757 | false | class Solution {\n public int firstUniqChar(String s) {\n HashMap <Character, Integer> ans = new HashMap <>();\n \n //go through the whole string, record the frequency of each letter\n for (int i = 0; i < s.length(); i ++){\n char c = s.charAt(i);\n if(ans.containsKe... | 6 | 0 | ['Java'] | 1 |
first-unique-character-in-a-string | java easiest solution without using extra-space | java-easiest-solution-without-using-extr-538p | \n public int firstUniqChar(String s) {\n for(int i = 0; i < s.length(); i++) {\n char c = s.charAt(i);\n if(s.indexOf(c) == s.last | kanika_matta | NORMAL | 2022-02-08T18:13:19.041769+00:00 | 2022-02-08T18:13:19.041813+00:00 | 652 | false | ```\n public int firstUniqChar(String s) {\n for(int i = 0; i < s.length(); i++) {\n char c = s.charAt(i);\n if(s.indexOf(c) == s.lastIndexOf(c)) {\n return i;\n }\n }\n \n return -1;\n }\n``` | 6 | 0 | ['Array', 'Java'] | 1 |
first-unique-character-in-a-string | C++ || Short and Easy to understand solution || Using Hashmap | c-short-and-easy-to-understand-solution-7mb73 | Please Upvote if you find this solution helpful\n\nclass Solution {\npublic:\n int firstUniqChar(string s) {\n unordered_map <char,int> mp;\n f | uk1124 | NORMAL | 2022-01-24T12:23:06.150845+00:00 | 2022-01-24T12:24:28.534709+00:00 | 373 | false | **Please Upvote if you find this solution helpful**\n```\nclass Solution {\npublic:\n int firstUniqChar(string s) {\n unordered_map <char,int> mp;\n for(int i=0; i<s.size(); i++) {\n mp[s[i]]++;\n }\n for(int i=0; i<s.size(); i++) {\n if(mp[s[i]] == 1) {\n ... | 6 | 0 | ['C', 'C++'] | 0 |
first-unique-character-in-a-string | Easy python solution O(n) | easy-python-solution-on-by-nirmitlakhani-z6co | \nclass Solution:\n def firstUniqChar(self, s: str) -> int:\n for i in range(len(s)):\n if s[i] not in s[i+1:] and s[i] not in s[:i]:\n | nirmitlakhani314 | NORMAL | 2022-01-10T11:02:56.619866+00:00 | 2022-01-10T11:02:56.619905+00:00 | 187 | false | ```\nclass Solution:\n def firstUniqChar(self, s: str) -> int:\n for i in range(len(s)):\n if s[i] not in s[i+1:] and s[i] not in s[:i]:\n return i\n break\n return -1\n \n``` | 6 | 0 | [] | 0 |
first-unique-character-in-a-string | Easy to understand in C++ || Hashmap | easy-to-understand-in-c-hashmap-by-lucif-y6lt | class Solution {\npublic:\n\n int firstUniqChar(string s) {\n unordered_map mp;\n for(int i=0;i<s.length();i++){\n mp[s[i]]++;\n | luciferraturi | NORMAL | 2021-12-30T17:39:58.969376+00:00 | 2021-12-30T17:39:58.969418+00:00 | 156 | false | class Solution {\npublic:\n\n int firstUniqChar(string s) {\n unordered_map<char,int> mp;\n for(int i=0;i<s.length();i++){\n mp[s[i]]++;\n }\n for(int i=0;i<s.length();i++){\n if(mp[s[i]]==1){\n return i;\n }\n }\n return -1;\n... | 6 | 0 | [] | 0 |
first-unique-character-in-a-string | Most Efficient Solution in C++ with Time Complexity O(n) Space O(1) Faster than 98%. | most-efficient-solution-in-c-with-time-c-7yrw | Here I have used a 2D array with 2 rows and 26 Columns so that there occurrence can be stored in row 1 with all corresponding characters repetitions and row 2 w | diwanshubansal | NORMAL | 2021-11-03T08:37:09.124743+00:00 | 2021-11-03T09:01:21.814295+00:00 | 145 | false | Here I have used a 2D array with **2 rows and 26 Columns** so that there occurrence can be stored in **row 1** with all corresponding **characters repetitions** and **row 2** with there last **occurrence index**. Finally I iterate through the 2D array and find the **first unique char with only one occurrences**.\n\n**T... | 6 | 0 | [] | 1 |
first-unique-character-in-a-string | Javascript Solution - Simple and Clear | javascript-solution-simple-and-clear-by-8gr92 | \nconst firstUniqChar = (s) => {\n for (let i = 0; i < s.length; ++i) if (s.indexOf(s[i]) === s.lastIndexOf(s[i])) return i;\n return -1;\n};\n\n\n\nResult\nR | ahmetcetinkaya | NORMAL | 2021-01-05T15:18:31.719133+00:00 | 2021-01-05T15:18:31.719180+00:00 | 1,440 | false | ```\nconst firstUniqChar = (s) => {\n for (let i = 0; i < s.length; ++i) if (s.indexOf(s[i]) === s.lastIndexOf(s[i])) return i;\n return -1;\n};\n```\n<a href="https://gist.github.com/ahmet-cetinkaya/479fe978f9130bd09be32e6e8f063822"><img src="https://img.shields.io/badge/gist-100000?style=for-the-badge&logo=github&l... | 6 | 0 | ['JavaScript'] | 3 |
first-unique-character-in-a-string | C# faster than 96.38%, less than 10.00% Mem, O(n) | c-faster-than-9638-less-than-1000-mem-on-xnzm | Runtime: 80 ms\nMemory Usage: 31.9 MB\n\n```\n public int FirstUniqChar(string s) {\n int[] counts = new int[\'z\'-\'a\'+1];\n \n for(int | ve7545 | NORMAL | 2020-02-26T19:06:39.374499+00:00 | 2020-02-26T19:06:39.374533+00:00 | 413 | false | Runtime: 80 ms\nMemory Usage: 31.9 MB\n\n```\n public int FirstUniqChar(string s) {\n int[] counts = new int[\'z\'-\'a\'+1];\n \n for(int i=0; i< s.Length; i++)\n {\n counts[s[i]-\'a\']++;\n }\n \n for(int i=0; i< s.Length; i++)\n {\n if (co... | 6 | 0 | [] | 0 |
first-unique-character-in-a-string | cpp solution that beats 97.96% | cpp-solution-that-beats-9796-by-leondele-tuq9 | \nclass Solution {\npublic:\n int firstUniqChar(string s) {\n vector<int> record(26, 0);\n for(char c: s) {\n int tmp = c - \'a\';\n | leondelee | NORMAL | 2019-01-21T16:25:42.129543+00:00 | 2019-01-21T16:25:42.129604+00:00 | 810 | false | ```\nclass Solution {\npublic:\n int firstUniqChar(string s) {\n vector<int> record(26, 0);\n for(char c: s) {\n int tmp = c - \'a\';\n record[tmp]++;\n }\n for(int i = 0; i < s.size(); i ++) {\n int tmp = s[i] - \'a\';\n if(record[tmp] == 1) re... | 6 | 0 | [] | 3 |
number-of-arithmetic-triplets | Check [n - diff] and [n - 2 * diff] | check-n-diff-and-n-2-diff-by-votrubac-v83k | C++\ncpp\nint arithmeticTriplets(vector<int>& nums, int diff) {\n int cnt[201] = {}, res = 0;\n for (auto n : nums) {\n if (n >= 2 * diff)\n | votrubac | NORMAL | 2022-08-07T04:04:54.423643+00:00 | 2022-08-07T04:04:54.423673+00:00 | 12,780 | false | **C++**\n```cpp\nint arithmeticTriplets(vector<int>& nums, int diff) {\n int cnt[201] = {}, res = 0;\n for (auto n : nums) {\n if (n >= 2 * diff)\n res += cnt[n - diff] && cnt[n - 2 * diff];\n cnt[n] = true;\n }\n return res;\n}\n``` | 134 | 2 | [] | 25 |
number-of-arithmetic-triplets | ✅ C++ Easy Hashmap solution | with explanation | c-easy-hashmap-solution-with-explanation-s46l | Hashing Technique.\n\nO(N) space and O(N) Time :\n\n1. Simply first store all the elements of array in a map or a set.\n2. Now again traverse the array and see | avaneeshyadav | NORMAL | 2022-08-07T08:38:43.751622+00:00 | 2022-08-07T11:43:52.899542+00:00 | 10,501 | false | # Hashing Technique.\n\n**O(N) space and O(N) Time :**\n\n1. Simply first store all the elements of array in a map or a set.\n2. Now again traverse the array and see for every element say \'x\', if there are two more elements present in map i.e x+diff and x-diff.\n3. If present then increment the count by 1.\n4. Return... | 127 | 1 | ['Array', 'C++'] | 10 |
number-of-arithmetic-triplets | ✅5 Method's || C++ || JAVA || PYTHON || Beginner Friendly🔥🔥🔥 | 5-methods-c-java-python-beginner-friendl-1i26 | Intuition\n Describe your first thoughts on how to solve this problem. \nThe "Number of Arithmetic Triplets" problem requires finding triplets in a given sorted | datpham0412 | NORMAL | 2024-04-20T07:57:35.904420+00:00 | 2024-04-20T07:57:35.904449+00:00 | 4,398 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe "Number of Arithmetic Triplets" problem requires finding triplets in a given sorted array nums such that two consecutive differences match a given value diff. This problem tests our ability to efficiently find specific sequences in an... | 126 | 0 | ['C++', 'Java', 'Python3'] | 9 |
number-of-arithmetic-triplets | [Java/Python 3] HashSet O(n) codes w/ analysis. | javapython-3-hashset-on-codes-w-analysis-n8mh | Credit to @dms6 for the improvement from 2 pass to 1 pass.\n\njava\n public int arithmeticTriplets(int[] nums, int diff) {\n int cnt = 0;\n Set | rock | NORMAL | 2022-08-07T04:04:49.226082+00:00 | 2023-05-29T12:49:15.485887+00:00 | 12,480 | false | Credit to **@dms6** for the improvement from 2 pass to 1 pass.\n\n```java\n public int arithmeticTriplets(int[] nums, int diff) {\n int cnt = 0;\n Set<Integer> seen = new HashSet<>();\n for (int num : nums) {\n if (seen.contains(num - diff) && seen.contains(num - diff * 2)) {\n ... | 83 | 0 | ['Java', 'Python3'] | 11 |
number-of-arithmetic-triplets | ✅Python || Easy Approach | python-easy-approach-by-chuhonghao01-or6g | \nclass Solution:\n def arithmeticTriplets(self, nums: List[int], diff: int) -> int:\n \n ans = 0\n n = len(nums)\n for i in rang | chuhonghao01 | NORMAL | 2022-08-07T22:01:06.148020+00:00 | 2022-08-19T01:56:40.485393+00:00 | 7,128 | false | ```\nclass Solution:\n def arithmeticTriplets(self, nums: List[int], diff: int) -> int:\n \n ans = 0\n n = len(nums)\n for i in range(n):\n if nums[i] + diff in nums and nums[i] + 2 * diff in nums:\n ans += 1\n \n return ans\n``` | 40 | 0 | ['Python', 'Python3'] | 8 |
number-of-arithmetic-triplets | Beats 100% of users || Step By Step Explain || Using HashMap || Easy to Understand || | beats-100-of-users-step-by-step-explain-m8bu4 | Abhiraj Pratap Singh \n\n---\n\n# if you like the solution Please UPVOTE it....\n\n---\n\n# Intuition\n Describe your first thoughts on how to solve this proble | abhirajpratapsingh | NORMAL | 2024-01-31T14:57:36.277233+00:00 | 2024-01-31T14:57:36.277263+00:00 | 1,233 | false | # Abhiraj Pratap Singh \n\n---\n\n# if you like the solution Please UPVOTE it....\n\n---\n\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- The intuition behind this code is to find arithmetic triplets in a given vector nums with a specified difference diff. An arithmetic triplet is ... | 24 | 0 | ['Array', 'Hash Table', 'Two Pointers', 'Enumeration', 'C++'] | 4 |
number-of-arithmetic-triplets | Java| Easy| HashSet | java-easy-hashset-by-sachinapex-9jvk | \nclass Solution {\n public int arithmeticTriplets(int[] nums, int diff) {\n \n\n Set<Integer> set = new HashSet<>();\n \n for( i | sachinapex | NORMAL | 2022-08-07T04:03:17.107346+00:00 | 2022-08-07T10:05:09.273439+00:00 | 2,674 | false | ```\nclass Solution {\n public int arithmeticTriplets(int[] nums, int diff) {\n \n\n Set<Integer> set = new HashSet<>();\n \n for( int num : nums){\n set.add(num);\n }\n \n int ans = 0;\n for( int num : nums){\n if(( set.contains(nu... | 24 | 0 | [] | 6 |
number-of-arithmetic-triplets | Beginner friendly [Python/JavaScript/Java] solutions | beginner-friendly-pythonjavascriptjava-s-fdi9 | \npython []\nclass Solution(object):\n def arithmeticTriplets(self, nums, diff):\n count = 0\n for num in nums:\n if num + diff in n | HimanshuBhoir | NORMAL | 2022-08-22T13:53:05.761215+00:00 | 2023-01-04T06:40:06.129627+00:00 | 3,568 | false | \n```python []\nclass Solution(object):\n def arithmeticTriplets(self, nums, diff):\n count = 0\n for num in nums:\n if num + diff in nums and num + diff*2 in nums:\n count += 1\n return count\n```\n\n```javascript []\nvar arithmeticTriplets = function(nums, diff) {\n ... | 23 | 0 | ['Python', 'Java', 'JavaScript'] | 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.