

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to return the index of first unique character without inbuilt functions using C#?
Create an empty new array of length 256, traverse through the entire string character by character and increment the value in the new array. At the end traverse the entire array and return the first character that has value 1.
Example 1
aabccd -→2 1 2 1 → Return the first character which is having count 1. That is b.
Example 2
using System; namespace ConsoleApplication{ public class Arrays{ public int ReturnIndexOfFirstUniqueCharachter(string s){ int index = -1; int[] arrayValues = new int[256]; for (int i = 0; i < s.Length; i++){ int value = s[i] - 'a'; arrayValues[value] += 1; } for (int i = 0; i < s.Length; i++){ int value = s[i] - 'a'; if (arrayValues[value] == 1){ index = i; break; } } return index; } } class Program{ static void Main(string[] args){ Arrays a = new Arrays(); Console.WriteLine(a.ReturnIndexOfFirstUniqueCharachter("bookisgreat")); Console.ReadLine(); } } }
Output
0
- Related Questions & Answers
- How to return the first unique character without using inbuilt functions using C#?
- Find the index of the first unique character in a given string using C++
- Return index of first repeating character in a string - JavaScript
- Python program to count upper and lower case characters without using inbuilt functions
- Count upper and lower case characters without using inbuilt functions in Python program
- Return the index of first character that appears twice in a string in JavaScript
- How to find the missing number and the repeated number in a sorted array without using any inbuilt functions using C#?
- Python Pandas - Return unique values in the index
- Python Pandas - Return number of unique elements in the Index object
- What are the different ways to find missing numbers in a sorted array without any inbuilt functions using C#?
- First Unique Character in a String in Python
- Python Pandas - Return Index without NaN values
- Finding the index of the first repeating character in a string in JavaScript
- Program to find the index of first Recurring Character in the given string in Python
- PHP – How to return the character count of a string using iconv_strlen()?
Advertisements