TORONTO KIDS COMPUTER CLUB | Markham Saturday 14:00 Java Homework 20.05.23.
17568
post-template-default,single,single-post,postid-17568,single-format-standard,ajax_fade,page_not_loaded,,qode-theme-ver-7.6.2,wpb-js-composer js-comp-ver-6.8.0,vc_responsive

Markham Saturday 14:00 Java Homework 20.05.23.

28 May Markham Saturday 14:00 Java Homework 20.05.23.

Question:
Given a string, find the first non-repeating character in it and return it’s index. If it doesn’t exist, return -1.

Sample Input 1:
Apple

Sample Output 1:
0

Explanation: 
“a” is the first character which is not repeating in the string apple and occur only once.

Sample Input 2:
lovelivesure

Sample Output 2:
1

Explanation: 
“o” is the first character which  does not repeat and occur only once.


Hint:
If you want to use HashMap with char keys and int values, please use the following code to create a HashMap.

HashMap<Character,Integer> map=new HashMap<Character,Integer>();
No Comments

Sorry, the comment form is closed at this time.