Cho một chuỗi S bao gồm các chữ cái Latin thường, nhiệm vụ là tìm ký tự không lặp lại đầu tiên trong S.S consisting of lowercase Latin Letters, the task is to find the first non-repeating character in S.
Examples:
Đầu vào: Đầu ra của Geekforgeeks đầu ra: FexPlanation: Vì ‘F, là ký tự đầu tiên trong chuỗi không lặp lại. “geeksforgeeks”
Output: f
Explanation: As ‘f’ is first character in the string which does not repeat.Đầu vào: Đầu ra thuật toán của người Viking: AExplanation: Như một ký tự đầu tiên là ký tự đầu tiên trong chuỗi không lặp lại. “algorithm”
Output: a
Explanation: As ‘a’ is first character in the string which does not repeat.
Cách tiếp cận ngây thơ:
Ý tưởng là lặp qua chuỗi và đối với mỗi ký tự, hãy kiểm tra sự xuất hiện của cùng một ký tự trong chuỗi. Nếu số lần xuất hiện của nó là 1 thì hãy trả về ký tự đó. Nếu không, tìm kiếm các ký tự còn lại.1 then return that character. Otherwise, search for the remaining characters.
Lưu ý: Trong Python để tìm sự xuất hiện của một ký tự trong chuỗi có một chuỗi hàm được xây dựng.Count []. In python to find the occurrence of a character in the string there is an In-Built Function string.count[].
Dưới đây là việc thực hiện phương pháp trên:
Python3
string
=
"geeksforgeeks"
index
=
First non-repeating character is f1
First non-repeating character is f2
First non-repeating character is f3
=
First non-repeating character is f5
First non-repeating character is f6
First non-repeating character is f7
First non-repeating character is f8
First non-repeating character is f9
First non-repeating character is f0____21
First non-repeating character is f2
=
=
First non-repeating character is f2
First non-repeating character is f6
First non-repeating character is f7
First non-repeating character is f3
First non-repeating character is f9__
First non-repeating character is f1
First non-repeating character is f7
First non-repeating character is f3
First non-repeating character is f0
First non-repeating character is f5
First non-repeating character is f6
First non-repeating character is f7
index
First non-repeating character is f9
=
First non-repeating character is f2
First non-repeating character is f1
index
=
First non-repeating character is f2
First non-repeating character is f6
First non-repeating character is f0
First non-repeating character is f9
First non-repeating character is f0
First non-repeating character is f1
First non-repeating character is f2
First non-repeating character is f5
First non-repeating character is f6
First non-repeating character is f0
First non-repeating character is f9
First non-repeating character is f0
First non-repeating character is f8
First non-repeating character is f9
Đầu ra
First non-repeating character is f
Độ phức tạp về thời gian: O [N2], Traverse qua chuỗi cho mỗi ký tự trong chuỗi kích thước N.AUXILIARY SPACE: O [1] O[N2], Traverse over the string for every character in the string of size N.
Auxiliary Space: O[1]
Ký tự không lặp lại đầu tiên bằng cách sử dụng hàm chuỗi tìm []:
Ý tưởng là tìm kiếm ký tự hiện tại trong chuỗi ngay sau lần xuất hiện đầu tiên trong chuỗi. Nếu ký tự được tìm thấy trong chuỗi còn lại thì hãy trả về ký tự đó. & NBSP;
Việc tìm kiếm được thực hiện bằng hàm find [] được xây dựng.in-built find[] function.
Dưới đây là việc thực hiện phương pháp này.
C++
string
0
string
1 string
2 string
3
string
4 string
5
string
6
First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f0
=
0 =
1First non-repeating character is f7
First non-repeating character is f1
=
4=
5=
6
=
5=
8=
9
"geeksforgeeks"
0"geeksforgeeks"
1
=
5"geeksforgeeks"
3"geeksforgeeks"
4
First non-repeating character is f7
"geeksforgeeks"
6First non-repeating character is f0
"geeksforgeeks"
6First non-repeating character is f0
=
8index
1=
5index
3"geeksforgeeks"
4
First non-repeating character is f0
"geeksforgeeks"
3"geeksforgeeks"
4"geeksforgeeks"
6
=
0
First non-repeating character is f00
string
6
First non-repeating character is f0
First non-repeating character is f03
"geeksforgeeks"
"geeksforgeeks"
4First non-repeating character is f0
First non-repeating character is f07
"geeksforgeeks"
6
Python3
First non-repeating character is f09
First non-repeating character is f10
First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f7
First non-repeating character is f8
First non-repeating character is f15
Các
=
5
First non-repeating character is f9
First non-repeating character is f0
First non-repeating character is f8
First non-repeating character is f31
=
5
First non-repeating character is f3
First non-repeating character is f0
"geeksforgeeks"
3First non-repeating character is f36
=
First non-repeating character is f38
First non-repeating character is f39
C#
string
1
First non-repeating character is f41
First non-repeating character is f42
First non-repeating character is f43
First non-repeating character is f44
First non-repeating character is f45
First non-repeating character is f0
First non-repeating character is f42
First non-repeating character is f43
string
4 First non-repeating character is f50
First non-repeating character is f51
First non-repeating character is f52
First non-repeating character is f0
string
6First non-repeating character is f7
First non-repeating character is f6
First non-repeating character is f0
=
0 First non-repeating character is f59
=
5
First non-repeating character is f1
First non-repeating character is f62
First non-repeating character is f63
First non-repeating character is f64
First non-repeating character is f63
First non-repeating character is f66
First non-repeating character is f67
=
9First non-repeating character is f67
First non-repeating character is f70
First non-repeating character is f63
First non-repeating character is f3
"geeksforgeeks"
4=
5"geeksforgeeks"
6
First non-repeating character is f7
"geeksforgeeks"
6First non-repeating character is f7
"geeksforgeeks"
3"geeksforgeeks"
4First non-repeating character is f0
"geeksforgeeks"
6First non-repeating character is f0
First non-repeating character is f84
First non-repeating character is f43
string
4 First non-repeating character is f87
First non-repeating character is f0
string
6First non-repeating character is f7
First non-repeating character is f51
First non-repeating character is f92
"geeksforgeeks"
"geeksforgeeks"
4First non-repeating character is f7
First non-repeating character is f07
First non-repeating character is f0
"geeksforgeeks"
6"geeksforgeeks"
6
JavaScript
First non-repeating character is f00
First non-repeating character is f01
First non-repeating character is f02
First non-repeating character is f03
First non-repeating character is f6
First non-repeating character is f05
First non-repeating character is f03
string
6First non-repeating character is f08
First non-repeating character is f1
First non-repeating character is f10
First non-repeating character is f08
string
6First non-repeating character is f13
First non-repeating character is f14
First non-repeating character is f13
First non-repeating character is f3
First non-repeating character is f08
"geeksforgeeks"
6First non-repeating character is f03
"geeksforgeeks"
6First non-repeating character is f03
"geeksforgeeks"
3"geeksforgeeks"
6
First non-repeating character is f24
First non-repeating character is f38
First non-repeating character is f39
First non-repeating character is f27
Đầu ra
First non-repeating character is f
Độ phức tạp về thời gian: O [N2], Traverse qua chuỗi cho mỗi ký tự trong chuỗi kích thước N.AUXILIARY SPACE: O [1]O[N2]
Auxiliary Space: O[1]
Ký tự không lặp lại đầu tiên bằng cách sử dụng hàm chuỗi tìm []:HashMap and two string traversals.
Ý tưởng là tìm kiếm ký tự hiện tại trong chuỗi ngay sau lần xuất hiện đầu tiên trong chuỗi. Nếu ký tự được tìm thấy trong chuỗi còn lại thì hãy trả về ký tự đó. & NBSP;unit frequency. This task could be done efficiently using a hash_map which will map the character to their respective frequencies and in which we can simultaneously update the frequency of any character we come across in constant time.
Việc tìm kiếm được thực hiện bằng hàm find [] được xây dựng.
- Dưới đây là việc thực hiện phương pháp này.hash_map that will map the character to their respective frequencies.
string
1string
2string
3string
4string
5hash_map.First non-repeating character is f
0First non-repeating character is f
6First non-repeating character is f
0=
0=
1frequency=1.First non-repeating character is f
7First non-repeating character is f
1=
4frequency>1 continue the traversal.First non-repeating character is f
0"geeksforgeeks"
6break the loop and print the current character as the answer.
=
0
First non-repeating character is f00
C++
First non-repeating character is f28
string
1 string
2 string
3
First non-repeating character is f32
=
0
First non-repeating character is f34
First non-repeating character is f35
First non-repeating character is f36
string
6
First non-repeating character is f0
=
0First non-repeating character is f40
=
0First non-repeating character is f42
First non-repeating character is f43
First non-repeating character is f0
First non-repeating character is f45
First non-repeating character is f0
=
0First non-repeating character is f48
First non-repeating character is f0
=
0 First non-repeating character is f51
First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f54
First non-repeating character is f7
First non-repeating character is f56
First non-repeating character is f0
"geeksforgeeks"
3 First non-repeating character is f59
"geeksforgeeks"
6
=
0
First non-repeating character is f62
First non-repeating character is f35
First non-repeating character is f36
string
6
First non-repeating character is f0
=
0First non-repeating character is f68
First non-repeating character is f0
=
0 First non-repeating character is f71
First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f74
First non-repeating character is f7
First non-repeating character is f1
First non-repeating character is f77
=
5
First non-repeating character is f79
=
5
First non-repeating character is f3
"geeksforgeeks"
4First non-repeating character is f7
"geeksforgeeks"
6First non-repeating character is f0
"geeksforgeeks"
6First non-repeating character is f0
First non-repeating character is f88
First non-repeating character is f89
First non-repeating character is f0
"geeksforgeeks"
3 First non-repeating character is f92
"geeksforgeeks"
6
=
0
First non-repeating character is f00
string
6
First non-repeating character is f0
First non-repeating character is f35
First non-repeating character is f99
"geeksforgeeks"
"geeksforgeeks"
4First non-repeating character is f0
=
0 First non-repeating character is f04
First non-repeating character is f0
First non-repeating character is f1
First non-repeating character is f07
First non-repeating character is f7
=
8index
1First non-repeating character is f63
index
3"geeksforgeeks"
4First non-repeating character is f0
First non-repeating character is f5
First non-repeating character is f7
=
8=
9First non-repeating character is f19
First non-repeating character is f20
First non-repeating character is f0
First non-repeating character is f22
First non-repeating character is f23
First non-repeating character is f0
"geeksforgeeks"
3 First non-repeating character is f26
"geeksforgeeks"
6
C
First non-repeating character is f28
First non-repeating character is f29
First non-repeating character is f32
=
0
First non-repeating character is f34
First non-repeating character is f35
First non-repeating character is f36
string
6
First non-repeating character is f0
=
0First non-repeating character is f40
=
0First non-repeating character is f42
First non-repeating character is f43
First non-repeating character is f0
First non-repeating character is f45
First non-repeating character is f0
=
0First non-repeating character is f48
First non-repeating character is f0
=
0 First non-repeating character is f51
First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f54
First non-repeating character is f7
First non-repeating character is f56
First non-repeating character is f0
"geeksforgeeks"
3 First non-repeating character is f59
"geeksforgeeks"
6
=
0
First non-repeating character is f62
First non-repeating character is f35
First non-repeating character is f36
string
6
First non-repeating character is f0
=
0First non-repeating character is f68
First non-repeating character is f0
=
0 First non-repeating character is f71
First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f74
First non-repeating character is f7
First non-repeating character is f1
First non-repeating character is f77
=
5
First non-repeating character is f79
=
5
First non-repeating character is f3
"geeksforgeeks"
4First non-repeating character is f7
"geeksforgeeks"
6First non-repeating character is f0
"geeksforgeeks"
6First non-repeating character is f0
First non-repeating character is f88
First non-repeating character is f89
First non-repeating character is f0
"geeksforgeeks"
3 First non-repeating character is f92
"geeksforgeeks"
6
=
0
First non-repeating character is f00
string
6
First non-repeating character is f0
First non-repeating character is f35
First non-repeating character is f99
"geeksforgeeks"
"geeksforgeeks"
4First non-repeating character is f0
=
0 First non-repeating character is f04
First non-repeating character is f0
First non-repeating character is f1
First non-repeating character is f07
First non-repeating character is f7
First non-repeating character is f07
First non-repeating character is f0
index
1First non-repeating character is f10
index
3First non-repeating character is f12
First non-repeating character is f0
First non-repeating character is f5
First non-repeating character is f7
First non-repeating character is f07
First non-repeating character is f0
First non-repeating character is f18
First non-repeating character is f19
First non-repeating character is f10
First non-repeating character is f21
First non-repeating character is f0
First non-repeating character is f22
First non-repeating character is f23
First non-repeating character is f0
"geeksforgeeks"
3 First non-repeating character is f26
"geeksforgeeks"
6
C
Java
First non-repeating character is f29
First non-repeating character is f30
First non-repeating character is f44
First non-repeating character is f45
First non-repeating character is f0
First non-repeating character is f43
First non-repeating character is f35
=
0 First non-repeating character is f37
First non-repeating character is f38
"geeksforgeeks"
4First non-repeating character is f0
First non-repeating character is f43
First non-repeating character is f35
First non-repeating character is f43
First non-repeating character is f44
First non-repeating character is f35
First non-repeating character is f46
First non-repeating character is f0
string
6First non-repeating character is f0
First non-repeating character is f43
string
4 First non-repeating character is f50
=
5
First non-repeating character is f61
First non-repeating character is f0
"geeksforgeeks"
6First non-repeating character is f7
First non-repeating character is f6
First non-repeating character is f0
=
0 First non-repeating character is f57
First non-repeating character is f58
First non-repeating character is f59
First non-repeating character is f0
string
6First non-repeating character is f7
First non-repeating character is f71
First non-repeating character is f0
First non-repeating character is f43
=
0 First non-repeating character is f67
First non-repeating character is f7
=
0 First non-repeating character is f74
First non-repeating character is f2
First non-repeating character is f76
First non-repeating character is f7
First non-repeating character is f6
First non-repeating character is f79
First non-repeating character is f58
First non-repeating character is f81
First non-repeating character is f63
First non-repeating character is f79
=
5
First non-repeating character is f1
First non-repeating character is f84
First non-repeating character is f2
First non-repeating character is f86
=
5"geeksforgeeks"
6
First non-repeating character is f7
"geeksforgeeks"
6First non-repeating character is f63
First non-repeating character is f3
"geeksforgeeks"
4First non-repeating character is f0
"geeksforgeeks"
6First non-repeating character is f7
"geeksforgeeks"
3 First non-repeating character is f92
First non-repeating character is f0
string
6First non-repeating character is f7
First non-repeating character is f09
"geeksforgeeks"
"geeksforgeeks"
4First non-repeating character is f0
First non-repeating character is f42
First non-repeating character is f43
string
4 First non-repeating character is f05
First non-repeating character is f7
First non-repeating character is f16
=
5
First non-repeating character is f18
First non-repeating character is f2
First non-repeating character is f63
First non-repeating character is f21
First non-repeating character is f22
First non-repeating character is f23
First non-repeating character is f24
First non-repeating character is f25
First non-repeating character is f63
First non-repeating character is f27
=
9First non-repeating character is f23
First non-repeating character is f30
First non-repeating character is f0
"geeksforgeeks"
6"geeksforgeeks"
6
Python3
First non-repeating character is f7
=
0 First non-repeating character is f04
First non-repeating character is f34
=
First non-repeating character is f38
First non-repeating character is f09
First non-repeating character is f38
First non-repeating character is f0
First non-repeating character is f40
=
First non-repeating character is f42
First non-repeating character is f58
First non-repeating character is f44444545
First non-repeating character is f46
First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f7
First non-repeating character is f8
First non-repeating character is f9
First non-repeating character is f7
First non-repeating character is f53
First non-repeating character is f54
First non-repeating character is f5555
First non-repeating character is f9
=
First non-repeating character is f0
"geeksforgeeks"
3 First non-repeating character is f61
First non-repeating character is f09
First non-repeating character is f63
First non-repeating character is f0
First non-repeating character is f40
=
First non-repeating character is f67
First non-repeating character is f0
index
__ First non-repeating character is f1
First non-repeating character is f2
First non-repeating character is f0
First non-repeating character is f40
=
First non-repeating character is f42
First non-repeating character is f58
First non-repeating character is f44444545
First non-repeating character is f46
First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f7
First non-repeating character is f8
First non-repeating character is f9
First non-repeating character is f7
First non-repeating character is f53
First non-repeating character is f54
First non-repeating character is f5555
First non-repeating character is f9
=
=
5
First non-repeating character is f3
First non-repeating character is f0
"geeksforgeeks"
3 First non-repeating character is f61
First non-repeating character is f09
First non-repeating character is f63
First non-repeating character is f0
First non-repeating character is f40
=
First non-repeating character is f67
First non-repeating character is f0
index
__ First non-repeating character is f1
First non-repeating character is f2
First non-repeating character is f0
First non-repeating character is f74
=
First non-repeating character is f58
First non-repeating character is f0
First non-repeating character is f9
First non-repeating character is f0
First non-repeating character is f1
First non-repeating character is f2
First non-repeating character is f5
First non-repeating character is f6
First non-repeating character is f0
First non-repeating character is f9
First non-repeating character is f0
First non-repeating character is f8
string
28C#
First non-repeating character is f7
First non-repeating character is f1
First non-repeating character is f53
First non-repeating character is f54
First non-repeating character is f555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555
=
=
=
=
First non-repeating character is f2
First non-repeating character is f6
=
5index
=
First non-repeating character is f94
First non-repeating character is f29
First non-repeating character is f30
First non-repeating character is f44
First non-repeating character is f45
First non-repeating character is f0
First non-repeating character is f43
First non-repeating character is f35
=
0 First non-repeating character is f37
First non-repeating character is f38
"geeksforgeeks"
4First non-repeating character is f0
First non-repeating character is f43
First non-repeating character is f35
First non-repeating character is f43
First non-repeating character is f44
First non-repeating character is f35
First non-repeating character is f46
First non-repeating character is f0
string
6First non-repeating character is f0
First non-repeating character is f43
string
4 First non-repeating character is f50
=
5string
60
First non-repeating character is f0
"geeksforgeeks"
6First non-repeating character is f0
First non-repeating character is f43
=
0 First non-repeating character is f62
First non-repeating character is f51
string
51First non-repeating character is f0
string
6First non-repeating character is f7
First non-repeating character is f71
First non-repeating character is f7
=
0 First non-repeating character is f71
First non-repeating character is f7
First non-repeating character is f6
string
78=
5
First non-repeating character is f1
string
81First non-repeating character is f63
First non-repeating character is f79
First non-repeating character is f63
First non-repeating character is f3
"geeksforgeeks"
4=
5"geeksforgeeks"
6
First non-repeating character is f7
"geeksforgeeks"
6First non-repeating character is f7
"geeksforgeeks"
3 First non-repeating character is f92
First non-repeating character is f0
"geeksforgeeks"
6First non-repeating character is f0
First non-repeating character is f42
First non-repeating character is f43
string
4 First non-repeating character is f87
First non-repeating character is f0
string
6First non-repeating character is f7
First non-repeating character is f51
=
05"geeksforgeeks"
"geeksforgeeks"
4First non-repeating character is f7
=
0 First non-repeating character is f04
First non-repeating character is f7
=
12=
5=
14
First non-repeating character is f63
First non-repeating character is f21
=
17First non-repeating character is f23
First non-repeating character is f24
=
20First non-repeating character is f23
First non-repeating character is f24
First non-repeating character is f25
First non-repeating character is f63
First non-repeating character is f27
=
26First non-repeating character is f23
First non-repeating character is f24
=
29 =
30First non-repeating character is f0
"geeksforgeeks"
6"geeksforgeeks"
6
PHP
=
34
=
35 =
36
=
37=
=
39=
40
First non-repeating character is f01
string
49=
43First non-repeating character is f2
string
6
First non-repeating character is f0
=
47 =
37"geeksforgeeks"
4First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f0
=
53 =
54____ ____7555=
53 =
57=
58
First non-repeating character is f0
=
43=
61=
53=
63Các
"geeksforgeeks"
6
First non-repeating character is f01
First non-repeating character is f62
=
43First non-repeating character is f2
string
6
First non-repeating character is f0
=
47 =
37"geeksforgeeks"
4First non-repeating character is f0
string
49=
43First non-repeating character is f12
First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f0
=
53 =
54First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f0
=
53 =
54____ ____7555=
53 =
57=
58
First non-repeating character is f0
=
43=
61=
53=
63First non-repeating character is f0
string
6Các
First non-repeating character is f7
string
6First non-repeating character is f01
First non-repeating character is f62
=
43First non-repeating character is f2
First non-repeating character is f0
=
86 =
87First non-repeating character is f7
"geeksforgeeks"
6First non-repeating character is f0
"geeksforgeeks"
6First non-repeating character is f7
First non-repeating character is f1
First non-repeating character is f0
=
37=
66=
43First non-repeating character is f42
=
53"geeksforgeeks"
12"geeksforgeeks"
6
‘
=
5
First non-repeating character is f3
"geeksforgeeks"
4"geeksforgeeks"
3 =
86"geeksforgeeks"
4
=
43 "geeksforgeeks"
17"geeksforgeeks"
"geeksforgeeks"
4
"geeksforgeeks"
46"geeksforgeeks"
47"geeksforgeeks"
4
First non-repeating character is f5
=
86 "geeksforgeeks"
36=
43
First non-repeating character is f12
=
5"geeksforgeeks"
54"geeksforgeeks"
45
First non-repeating character is f10
=
43First non-repeating character is f42
=
86"geeksforgeeks"
60"geeksforgeeks"
61
First non-repeating character is f
1First non-repeating character is f
0=
86 "geeksforgeeks"
42
First non-repeating character is f
"geeksforgeeks"
43 "geeksforgeeks"
44 "geeksforgeeks"
45O[N], Traversing over the string of size N
Auxiliary Space: O[256], To store the frequency of the characters in the string.
"geeksforgeeks"
43 "geeksforgeeks"
51"geeksforgeeks"
45HashMap and single string traversal
Đầu ra
Độ phức tạp về thời gian: O [n], đi qua chuỗi không gian kích thước nauxiliary: O [256], để lưu trữ tần số của các ký tự trong chuỗi.
- Ký tự không lặp lại đầu tiên bằng cách sử dụng hashmap và chuỗi chuỗi đơncount_array which will have two fields namely frequency, first occurrence of a character.
- Ý tưởng là tạo ra một mảng đếm thay vì hash_map có số lượng ký tự tối đa [256]. Tăng cường mảng đếm bằng cách lưu trữ không chỉ tính mà còn chỉ là chỉ số của lần đầu tiên một nhân vật gặp phải. Vì vậy, khi nói đến việc tìm kiếm người không phóng thích đầu tiên, chỉ cần quét mảng đếm, thay vì chuỗi.count_array is 256.
- Thực hiện theo các bước dưới đây để giải quyết vấn đề:
- Tạo một Count_array sẽ có hai trường là tần số, lần đầu tiên xuất hiện của một ký tự.
- Kích thước của Count_array là 256.
- Traverse Chuỗi đã cho bằng một con trỏ.count_array[] and find the character with the least first occurrence value and frequency value as unity.
- Tăng số lượng các ký tự hiện tại và cập nhật sự xuất hiện.
Bây giờ, ở đây, một sản phẩm bắt, mảng sẽ chứa sự xuất hiện đầu tiên hợp lệ của nhân vật có tần suất thống nhất. Nếu không, sự xuất hiện đầu tiên tiếp tục cập nhật.
C++
string
0
Bây giờ đi qua Count_array [] và tìm ký tự có giá trị xuất hiện và giá trị tần số ít nhất là thống nhất.
First non-repeating character is f32
Trả lại nhân vật đó.
string
6
First non-repeating character is f0
"geeksforgeeks"
73=
0"geeksforgeeks"
75=
0"geeksforgeeks"
77Dưới đây là việc thực hiện phương pháp trên.
First non-repeating character is f7
"geeksforgeeks"
84First non-repeating character is f7
"geeksforgeeks"
86First non-repeating character is f0
"geeksforgeeks"
6string
1 string
2 string
3
=
0
First non-repeating character is f62
First non-repeating character is f35
First non-repeating character is f36
First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f0
=
0 "geeksforgeeks"
82=
5index
01
First non-repeating character is f0
=
0 "geeksforgeeks"
91"geeksforgeeks"
6
First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f0
=
0 "geeksforgeeks"
96string
6
First non-repeating character is f7
First non-repeating character is f1
"geeksforgeeks"
99First non-repeating character is f0
"geeksforgeeks"
3 index
04=
0
First non-repeating character is f00
First non-repeating character is f7
First non-repeating character is f07
First non-repeating character is f0
index
23First non-repeating character is f10
index
25First non-repeating character is f12
First non-repeating character is f0
First non-repeating character is f5
First non-repeating character is f7
First non-repeating character is f07
First non-repeating character is f0
=
26First non-repeating character is f10
index
34First non-repeating character is f19
First non-repeating character is f10
First non-repeating character is f21
First non-repeating character is f0
First non-repeating character is f35
First non-repeating character is f99
"geeksforgeeks"
"geeksforgeeks"
4"geeksforgeeks"
6
First non-repeating character is f
0=
0 First non-repeating character is f
04
index
42
First non-repeating character is f28
First non-repeating character is f29
First non-repeating character is f32
First non-repeating character is f0
First non-repeating character is f1
index
19First non-repeating character is f0
"geeksforgeeks"
3 First non-repeating character is f26
C
index
54
index
46 index
47
string
6
First non-repeating character is f0
=
0 First non-repeating character is f59
First non-repeating character is f0
=
0 First non-repeating character is f92
First non-repeating character is f0
=
0 First non-repeating character is f51
First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f74
First non-repeating character is f7
index
79First non-repeating character is f7
First non-repeating character is f1
index
82=
5index
84
First non-repeating character is f0
"geeksforgeeks"
6First non-repeating character is f0
"geeksforgeeks"
3 First non-repeating character is f59
"geeksforgeeks"
6
=
0
First non-repeating character is f62
First non-repeating character is f35
First non-repeating character is f36
string
6
First non-repeating character is f0
index
46 index
98First non-repeating character is f0
=
0 First non-repeating character is f001
First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f004
First non-repeating character is f7
First non-repeating character is f1
First non-repeating character is f007
=
5
First non-repeating character is f009
First non-repeating character is f0
"geeksforgeeks"
6First non-repeating character is f0
First non-repeating character is f88
First non-repeating character is f89
First non-repeating character is f0
"geeksforgeeks"
3 First non-repeating character is f017
"geeksforgeeks"
6
=
0
First non-repeating character is f00
string
6
First non-repeating character is f0
First non-repeating character is f35
First non-repeating character is f99
"geeksforgeeks"
"geeksforgeeks"
4First non-repeating character is f0
=
0 First non-repeating character is f04
First non-repeating character is f0
First non-repeating character is f1
index
19First non-repeating character is f7
First non-repeating character is f07
First non-repeating character is f0
"geeksforgeeks"
44First non-repeating character is f10
"geeksforgeeks"
47First non-repeating character is f12
First non-repeating character is f0
First non-repeating character is f5
First non-repeating character is f7
First non-repeating character is f07
First non-repeating character is f0
=
26First non-repeating character is f10
index
34First non-repeating character is f19
First non-repeating character is f10
First non-repeating character is f21
First non-repeating character is f0
First non-repeating character is f22
First non-repeating character is f23
First non-repeating character is f0
"geeksforgeeks"
3 First non-repeating character is f26
"geeksforgeeks"
6
Java
First non-repeating character is f29
First non-repeating character is f059
First non-repeating character is f44
First non-repeating character is f061
First non-repeating character is f0
=
0 First non-repeating character is f064
First non-repeating character is f0
First non-repeating character is f42
First non-repeating character is f067
=
0 First non-repeating character is f069
First non-repeating character is f0
string
6
First non-repeating character is f7
First non-repeating character is f073
First non-repeating character is f074
First non-repeating character is f2
"geeksforgeeks"
4First non-repeating character is f7
First non-repeating character is f073
First non-repeating character is f079
First non-repeating character is f0
"geeksforgeeks"
6First non-repeating character is f0
First non-repeating character is f42
string
4 First non-repeating character is f085
First non-repeating character is f073
First non-repeating character is f087
"geeksforgeeks"
6
First non-repeating character is f44
First non-repeating character is f45
First non-repeating character is f0
First non-repeating character is f43
First non-repeating character is f35
=
0 First non-repeating character is f37
First non-repeating character is f38
"geeksforgeeks"
4First non-repeating character is f0
First non-repeating character is f43
First non-repeating character is f100
First non-repeating character is f7
"geeksforgeeks"
17First non-repeating character is f44
First non-repeating character is f104
First non-repeating character is f0
First non-repeating character is f43
string
4 First non-repeating character is f50
First non-repeating character is f0
string
6First non-repeating character is f7
First non-repeating character is f6
First non-repeating character is f0
=
0 First non-repeating character is f57
First non-repeating character is f58
First non-repeating character is f81
=
5
First non-repeating character is f1
First non-repeating character is f120
First non-repeating character is f63
First non-repeating character is f122
=
5"geeksforgeeks"
6
=
5
First non-repeating character is f5
string
6First non-repeating character is f63
First non-repeating character is f129
First non-repeating character is f44
First non-repeating character is f131
=
5"geeksforgeeks"
6
First non-repeating character is f7
"geeksforgeeks"
6First non-repeating character is f0
"geeksforgeeks"
6First non-repeating character is f0
First non-repeating character is f43
=
0 First non-repeating character is f67
First non-repeating character is f0
string
6First non-repeating character is f7
First non-repeating character is f71
First non-repeating character is f7
=
0 First non-repeating character is f148
First non-repeating character is f7
First non-repeating character is f6
First non-repeating character is f151
First non-repeating character is f19
First non-repeating character is f153
=
5=
0
First non-repeating character is f156
=
5=
0
First non-repeating character is f159
=
5
First non-repeating character is f1
First non-repeating character is f162
First non-repeating character is f2
First non-repeating character is f164
First non-repeating character is f63
First non-repeating character is f166
=
5"geeksforgeeks"
6
First non-repeating character is f7
"geeksforgeeks"
6First non-repeating character is f7
"geeksforgeeks"
3 First non-repeating character is f017
First non-repeating character is f0
"geeksforgeeks"
6First non-repeating character is f0
First non-repeating character is f42
First non-repeating character is f43
string
4 First non-repeating character is f05
First non-repeating character is f0
string
6First non-repeating character is f7
First non-repeating character is f09
"geeksforgeeks"
"geeksforgeeks"
4First non-repeating character is f7
=
0 First non-repeating character is f04
First non-repeating character is f7
First non-repeating character is f16
=
5
First non-repeating character is f193
First non-repeating character is f63
First non-repeating character is f21
First non-repeating character is f196
First non-repeating character is f23
First non-repeating character is f24
First non-repeating character is f199
First non-repeating character is f63
First non-repeating character is f27
=
9First non-repeating character is f23
First non-repeating character is f30
First non-repeating character is f0
"geeksforgeeks"
6"geeksforgeeks"
6
Python3
First non-repeating character is f29
First non-repeating character is f209
First non-repeating character is f34
=
First non-repeating character is f38
First non-repeating character is f09
First non-repeating character is f62
First non-repeating character is f215
First non-repeating character is f216
First non-repeating character is f0
First non-repeating character is f218
=
First non-repeating character is f220
First non-repeating character is f6
First non-repeating character is f7
First non-repeating character is f8
First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f7
First non-repeating character is f8
First non-repeating character is f224
First non-repeating character is f231
First non-repeating character is f7
First non-repeating character is f233
=
First non-repeating character is f42
First non-repeating character is f58
"geeksforgeeks"
75First non-repeating character is f58
First non-repeating character is f239
First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f7
First non-repeating character is f8
First non-repeating character is f224
First non-repeating character is f0
First non-repeating character is f246
First non-repeating character is f0
First non-repeating character is f215
First non-repeating character is f249
Các
Các
First non-repeating character is f0
First non-repeating character is f272
=
First non-repeating character is f274
First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f7
First non-repeating character is f8
First non-repeating character is f224
First non-repeating character is f231
First non-repeating character is f7
First non-repeating character is f233
=
First non-repeating character is f42
First non-repeating character is f58
"geeksforgeeks"
75First non-repeating character is f58
First non-repeating character is f239
First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f7
First non-repeating character is f8
First non-repeating character is f224
First non-repeating character is f0
First non-repeating character is f246
First non-repeating character is f0
First non-repeating character is f215
First non-repeating character is f249
Các
Các
First non-repeating character is f0
First non-repeating character is f272
=
First non-repeating character is f274
Các
First non-repeating character is f0
First non-repeating character is f9
First non-repeating character is f0
First non-repeating character is f1
First non-repeating character is f2
First non-repeating character is f5
First non-repeating character is f6
=
5
First non-repeating character is f272
=
First non-repeating character is f293
First non-repeating character is f294
First non-repeating character is f2
First non-repeating character is f296
C#
First non-repeating character is f0
"geeksforgeeks"
3 First non-repeating character is f299
First non-repeating character is f215
=
"geeksforgeeks"
First non-repeating character is f44
First non-repeating character is f061
First non-repeating character is f0
=
0 First non-repeating character is f064
First non-repeating character is f0
First non-repeating character is f42
First non-repeating character is f067
=
0 First non-repeating character is f069
First non-repeating character is f0
string
6First non-repeating character is f7
First non-repeating character is f073
First non-repeating character is f346
First non-repeating character is f7
First non-repeating character is f073
First non-repeating character is f079
First non-repeating character is f0
"geeksforgeeks"
6First non-repeating character is f0
First non-repeating character is f42
string
4 First non-repeating character is f085
First non-repeating character is f073
First non-repeating character is f087
"geeksforgeeks"
6
First non-repeating character is f44
First non-repeating character is f45
First non-repeating character is f0
First non-repeating character is f43
First non-repeating character is f35
=
0 First non-repeating character is f37
First non-repeating character is f38
"geeksforgeeks"
4First non-repeating character is f0
First non-repeating character is f43
First non-repeating character is f100
First non-repeating character is f7
"geeksforgeeks"
17First non-repeating character is f44
First non-repeating character is f104
First non-repeating character is f0
First non-repeating character is f43
string
4 First non-repeating character is f50
First non-repeating character is f0
string
6First non-repeating character is f7
First non-repeating character is f6
First non-repeating character is f0
=
0 First non-repeating character is f392
=
5
First non-repeating character is f1
First non-repeating character is f395
First non-repeating character is f63
First non-repeating character is f397
=
5"geeksforgeeks"
6
=
5
First non-repeating character is f5
string
6First non-repeating character is f63
First non-repeating character is f404
First non-repeating character is f44
First non-repeating character is f406
=
5"geeksforgeeks"
6
First non-repeating character is f7
"geeksforgeeks"
6First non-repeating character is f0
"geeksforgeeks"
6First non-repeating character is f0
First non-repeating character is f84
First non-repeating character is f43
=
0 First non-repeating character is f62
First non-repeating character is f51
string
51First non-repeating character is f0
string
6First non-repeating character is f7
First non-repeating character is f71
First non-repeating character is f7
=
0 First non-repeating character is f426
=
0First non-repeating character is f428
First non-repeating character is f7
First non-repeating character is f6
string
78=
5
First non-repeating character is f1
First non-repeating character is f434
First non-repeating character is f63
First non-repeating character is f436
First non-repeating character is f63
First non-repeating character is f438
=
5"geeksforgeeks"
6
First non-repeating character is f7
"geeksforgeeks"
6First non-repeating character is f7
"geeksforgeeks"
3 First non-repeating character is f017
First non-repeating character is f0
"geeksforgeeks"
6First non-repeating character is f0
First non-repeating character is f42
First non-repeating character is f43
string
4 First non-repeating character is f452
First non-repeating character is f51
First non-repeating character is f454
First non-repeating character is f0
string
6First non-repeating character is f7
First non-repeating character is f51
=
05"geeksforgeeks"
"geeksforgeeks"
4First non-repeating character is f7
=
0 First non-repeating character is f04
First non-repeating character is f7
=
12=
5
First non-repeating character is f468
=
0First non-repeating character is f470
First non-repeating character is f63
First non-repeating character is f21
First non-repeating character is f196
First non-repeating character is f23
First non-repeating character is f24
First non-repeating character is f199
First non-repeating character is f63
First non-repeating character is f27
=
9First non-repeating character is f23
=
30First non-repeating character is f0
"geeksforgeeks"
6"geeksforgeeks"
6
JavaScript
First non-repeating character is f00
First non-repeating character is f486
First non-repeating character is f01
First non-repeating character is f488
string
6
First non-repeating character is f0
First non-repeating character is f491
First non-repeating character is f44
First non-repeating character is f493
First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f496
First non-repeating character is f7
First non-repeating character is f498
First non-repeating character is f0
"geeksforgeeks"
6First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f503
First non-repeating character is f7
First non-repeating character is f505
First non-repeating character is f7
First non-repeating character is f507
First non-repeating character is f0
"geeksforgeeks"
6First non-repeating character is f0
First non-repeating character is f511
First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f514
First non-repeating character is f7
First non-repeating character is f1
First non-repeating character is f517
=
5
First non-repeating character is f519
First non-repeating character is f0
"geeksforgeeks"
3 index
04"geeksforgeeks"
6
First non-repeating character is f524
"geeksforgeeks"
"geeksforgeeks"
4First non-repeating character is f527
First non-repeating character is f1
First non-repeating character is f529
First non-repeating character is f0
First non-repeating character is f531
First non-repeating character is f1
First non-repeating character is f12
First non-repeating character is f5
First non-repeating character is f0
First non-repeating character is f531
=
9First non-repeating character is f538
First non-repeating character is f27
Đầu ra
First non-repeating character is f
Độ phức tạp về thời gian: O [n], vì chuỗi cần được đi qua ít nhất một lần. Không gian của bạn: O [256], không gian bị chiếm bởi việc sử dụng Count_array/Hash_map để theo dõi tần số. O[N], As the string
needs to be traversed at least once.
Auxiliary Space: O[256], Space is occupied by the use of count_array/hash_map to keep track of frequency.
Ký tự không lặp lại đầu tiên bằng cách sử dụng mảng đếm và chuỗi chuỗi đơn:
Ý tưởng là đánh dấu các yếu tố lặp đi lặp lại với một số giá trị, hãy nói với -2 và người lặp lại một lần sẽ được đánh dấu bằng chỉ số hiện tại.
Thực hiện theo các bước dưới đây để giải quyết vấn đề:
- Tạo một mảng đếm có số lượng ký tự tối đa [256] và khởi tạo tất cả các phần tử trong mảng này thành -1. & Nbsp;-1.
- Sau đó lặp qua ký tự chuỗi theo ký tự và kiểm tra xem phần tử mảng có ký tự này là chỉ mục là -1 hay không. & Nbsp;-1 or not.
- Nếu đó là -1 thì hãy thay đổi nó thành i và. Nếu nó không phải là -1, thì điều này có nghĩa là ký tự này đã xuất hiện trước đó, vì vậy hãy thay đổi nó thành -2. & Nbsp;-1 then change it to i and. If it is not -1, then this means that this character already appeared before, so change it to -2.
- Cuối cùng, tất cả các ký tự lặp lại sẽ được thay đổi thành -2 và tất cả các ký tự không lặp lại sẽ chứa chỉ mục nơi chúng xảy ra. & NBSP;-2 and all non-repeating characters will contain the index where they occur.
- Bây giờ, chỉ cần lặp qua tất cả các ký tự không lặp lại và tìm chỉ mục tối thiểu hoặc chỉ mục đầu tiên.
Dưới đây là việc thực hiện phương pháp trên.
C++
First non-repeating character is f540
First non-repeating character is f28
string
1 string
2 string
3
=
0
First non-repeating character is f546
string
6
First non-repeating character is f0
=
0 First non-repeating character is f550
First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f0
=
0 First non-repeating character is f555
First non-repeating character is f7
First non-repeating character is f557
First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f0
=
0 First non-repeating character is f562
First non-repeating character is f7
First non-repeating character is f1
First non-repeating character is f565
=
5
First non-repeating character is f567
First non-repeating character is f7
"geeksforgeeks"
6First non-repeating character is f7
First non-repeating character is f5
string
6=
5
First non-repeating character is f574
First non-repeating character is f7
"geeksforgeeks"
6First non-repeating character is f0
"geeksforgeeks"
6First non-repeating character is f0
=
0 "geeksforgeeks"
91First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f0
=
0 First non-repeating character is f586
First non-repeating character is f7
First non-repeating character is f1
First non-repeating character is f589
=
5
First non-repeating character is f591
First non-repeating character is f0
"geeksforgeeks"
6First non-repeating character is f0____21
First non-repeating character is f596
First non-repeating character is f7
"geeksforgeeks"
3 First non-repeating character is f599
First non-repeating character is f0
First non-repeating character is f5
First non-repeating character is f7
"geeksforgeeks"
3 index
04"geeksforgeeks"
6
=
0
First non-repeating character is f00
string
6
First non-repeating character is f0
First non-repeating character is f610
First non-repeating character is f0
=
05"geeksforgeeks"
"geeksforgeeks"
4First non-repeating character is f0
=
0 First non-repeating character is f617
First non-repeating character is f0
First non-repeating character is f1
First non-repeating character is f620
First non-repeating character is f7
=
8index
1First non-repeating character is f63
index
3"geeksforgeeks"
4First non-repeating character is f0
First non-repeating character is f5
First non-repeating character is f7
=
8=
9First non-repeating character is f19
First non-repeating character is f633
First non-repeating character is f0
"geeksforgeeks"
3 First non-repeating character is f26
"geeksforgeeks"
6
Java
First non-repeating character is f42
First non-repeating character is f44
First non-repeating character is f45
First non-repeating character is f0
First non-repeating character is f42
First non-repeating character is f43
=
0 First non-repeating character is f67
First non-repeating character is f0
string
6First non-repeating character is f7
=
0First non-repeating character is f650
=
5"geeksforgeeks"
17
First non-repeating character is f44
=
0First non-repeating character is f42
First non-repeating character is f38
First non-repeating character is f657
First non-repeating character is f7
First non-repeating character is f6
First non-repeating character is f0
=
0 First non-repeating character is f57
First non-repeating character is f58
First non-repeating character is f664
First non-repeating character is f38
First non-repeating character is f666
=
5
First non-repeating character is f668
First non-repeating character is f2
"geeksforgeeks"
4First non-repeating character is f7
First non-repeating character is f6
First non-repeating character is f0
=
0 First non-repeating character is f57
First non-repeating character is f58
First non-repeating character is f81
=
5
First non-repeating character is f1
First non-repeating character is f680
First non-repeating character is f2
First non-repeating character is f86
First non-repeating character is f63
First non-repeating character is f684
=
5"geeksforgeeks"
6
=
5
First non-repeating character is f5
string
6First non-repeating character is f63
First non-repeating character is f691
First non-repeating character is f692
"geeksforgeeks"
4=
5"geeksforgeeks"
6
First non-repeating character is f7
"geeksforgeeks"
6First non-repeating character is f7
=
0 First non-repeating character is f700
First non-repeating character is f7
First non-repeating character is f6
First non-repeating character is f0
=
0 First non-repeating character is f57
First non-repeating character is f58
First non-repeating character is f664
First non-repeating character is f38
First non-repeating character is f709
=
5
First non-repeating character is f1
First non-repeating character is f712
First non-repeating character is f58
First non-repeating character is f2
First non-repeating character is f63
First non-repeating character is f716
First non-repeating character is f7
"geeksforgeeks"
6First non-repeating character is f7
First non-repeating character is f1
First non-repeating character is f721
=
5"geeksforgeeks"
3
First non-repeating character is f1
First non-repeating character is f2
"geeksforgeeks"
4First non-repeating character is f7
First non-repeating character is f5
=
5"geeksforgeeks"
3 index
04
First non-repeating character is f0
"geeksforgeeks"
6First non-repeating character is f0
First non-repeating character is f42
First non-repeating character is f43
string
4 First non-repeating character is f738
First non-repeating character is f0
string
6First non-repeating character is f7
First non-repeating character is f742
First non-repeating character is f7
=
05"geeksforgeeks"
"geeksforgeeks"
4First non-repeating character is f7
=
0 First non-repeating character is f617
First non-repeating character is f7
First non-repeating character is f1
First non-repeating character is f752
First non-repeating character is f2
First non-repeating character is f2
=
5
First non-repeating character is f16
First non-repeating character is f63
First non-repeating character is f1
First non-repeating character is f12
First non-repeating character is f7
First non-repeating character is f5
=
5
First non-repeating character is f16
First non-repeating character is f63
=
9First non-repeating character is f63
First non-repeating character is f767
First non-repeating character is f0
"geeksforgeeks"
6"geeksforgeeks"
6
Python3
First non-repeating character is f29
First non-repeating character is f209
First non-repeating character is f09
First non-repeating character is f62
First non-repeating character is f215
First non-repeating character is f216
First non-repeating character is f0
First non-repeating character is f778__
First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f7
First non-repeating character is f8
First non-repeating character is f224
First non-repeating character is f0
First non-repeating character is f246
First non-repeating character is f0
First non-repeating character is f215
First non-repeating character is f249
Các
Các
First non-repeating character is f7
First non-repeating character is f5
First non-repeating character is f6
Các
First non-repeating character is f0
First non-repeating character is f272
=
First non-repeating character is f274
First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f7
First non-repeating character is f8
First non-repeating character is f224
First non-repeating character is f0
First non-repeating character is f38
First non-repeating character is f216
First non-repeating character is f7
First non-repeating character is f1
First non-repeating character is f846
=
First non-repeating character is f58
First non-repeating character is f216
=
5
First non-repeating character is f272
=
First non-repeating character is f293
First non-repeating character is f854
First non-repeating character is f0
First non-repeating character is f1
First non-repeating character is f857
=
__ First non-repeating character is f312
First non-repeating character is f7
"geeksforgeeks"
3 First non-repeating character is f1
First non-repeating character is f2
First non-repeating character is f0
First non-repeating character is f5
First non-repeating character is f6
First non-repeating character is f7
"geeksforgeeks"
3 First non-repeating character is f299
First non-repeating character is f215
=
"geeksforgeeks"
First non-repeating character is f874
=
First non-repeating character is f62
First non-repeating character is f215
First non-repeating character is f2
First non-repeating character is f1
First non-repeating character is f880
=
__ First non-repeating character is f1
First non-repeating character is f2
First non-repeating character is f216
First non-repeating character is f0
First non-repeating character is f9
First non-repeating character is f0
First non-repeating character is f1
First non-repeating character is f2
First non-repeating character is f5
First non-repeating character is f6
First non-repeating character is f0
First non-repeating character is f9
First non-repeating character is f0
=
9 First non-repeating character is f9
First non-repeating character is f898
First non-repeating character is f0
First non-repeating character is f215
First non-repeating character is f901
C#
string
1
First non-repeating character is f41
First non-repeating character is f42
First non-repeating character is f44
First non-repeating character is f45
First non-repeating character is f0
First non-repeating character is f42
First non-repeating character is f43
=
0 First non-repeating character is f62
First non-repeating character is f51
string
51First non-repeating character is f0
string
6First non-repeating character is f7
=
0First non-repeating character is f650
=
5"geeksforgeeks"
17
First non-repeating character is f44
=
0First non-repeating character is f923
First non-repeating character is f7
First non-repeating character is f6
First non-repeating character is f0
=
0 First non-repeating character is f555
=
5
First non-repeating character is f557
First non-repeating character is f7
First non-repeating character is f6
First non-repeating character is f0
=
0 First non-repeating character is f392
=
5
First non-repeating character is f1
First non-repeating character is f565
First non-repeating character is f63
First non-repeating character is f567
=
5"geeksforgeeks"
6
=
5
First non-repeating character is f5
string
6First non-repeating character is f63
First non-repeating character is f574
=
5"geeksforgeeks"
6
First non-repeating character is f7
"geeksforgeeks"
6First non-repeating character is f7
=
0 First non-repeating character is f954
First non-repeating character is f7
First non-repeating character is f6
First non-repeating character is f0
=
0 First non-repeating character is f586
=
5
First non-repeating character is f1
First non-repeating character is f589
First non-repeating character is f63
First non-repeating character is f964
First non-repeating character is f7
"geeksforgeeks"
6First non-repeating character is f7
First non-repeating character is f1
First non-repeating character is f969
=
5"geeksforgeeks"
3
First non-repeating character is f599
First non-repeating character is f7
First non-repeating character is f5
=
5"geeksforgeeks"
3 index
04
First non-repeating character is f0
"geeksforgeeks"
6First non-repeating character is f0
First non-repeating character is f42
First non-repeating character is f43
string
4 First non-repeating character is f738
First non-repeating character is f0
string
6First non-repeating character is f7
=
0 First non-repeating character is f617
First non-repeating character is f7
=
05"geeksforgeeks"
"geeksforgeeks"
4First non-repeating character is f7
=
0 First non-repeating character is f617
First non-repeating character is f7
First non-repeating character is f1
First non-repeating character is f752
First non-repeating character is f2
First non-repeating character is f2
=
5=
12
First non-repeating character is f63
First non-repeating character is f1
First non-repeating character is f12
First non-repeating character is f7
First non-repeating character is f5
=
5=
12
First non-repeating character is f63
=
9First non-repeating character is f63
First non-repeating character is f012
First non-repeating character is f0
"geeksforgeeks"
6"geeksforgeeks"
6
First non-repeating character is f
29 First non-repeating character is f
209
First non-repeating character is f00
First non-repeating character is f09
First non-repeating character is f62
First non-repeating character is f215
First non-repeating character is f216
string
6
First non-repeating character is f0
First non-repeating character is f778__
First non-repeating character is f0
First non-repeating character is f026
First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f7
First non-repeating character is f8
First non-repeating character is f224
First non-repeating character is f0
First non-repeating character is f246
First non-repeating character is f0
First non-repeating character is f215
First non-repeating character is f249
First non-repeating character is f7
First non-repeating character is f557
Các
First non-repeating character is f0
string
6First non-repeating character is f7
First non-repeating character is f1
First non-repeating character is f043
First non-repeating character is f7
string
6=
5
First non-repeating character is f047
First non-repeating character is f7
"geeksforgeeks"
6First non-repeating character is f7
First non-repeating character is f5
First non-repeating character is f7
string
6=
5
First non-repeating character is f055
First non-repeating character is f7
"geeksforgeeks"
6First non-repeating character is f0
"geeksforgeeks"
6Các
Các
First non-repeating character is f0
First non-repeating character is f272
=
First non-repeating character is f274
=
5
First non-repeating character is f716
First non-repeating character is f0
"geeksforgeeks"
6First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f7
First non-repeating character is f8
First non-repeating character is f224
First non-repeating character is f0
First non-repeating character is f38
First non-repeating character is f216
First non-repeating character is f7
First non-repeating character is f1
First non-repeating character is f846
=
First non-repeating character is f58
First non-repeating character is f216
"geeksforgeeks"
6
=
5
First non-repeating character is f272
=
First non-repeating character is f293
First non-repeating character is f854
First non-repeating character is f0
=
05"geeksforgeeks"
"geeksforgeeks"
4First non-repeating character is f0
First non-repeating character is f1
First non-repeating character is f857
=
__ First non-repeating character is f312
First non-repeating character is f7
"geeksforgeeks"
3 First non-repeating character is f1
First non-repeating character is f2
First non-repeating character is f7
First non-repeating character is f531
First non-repeating character is f1
First non-repeating character is f12
First non-repeating character is f0
First non-repeating character is f5
First non-repeating character is f7
First non-repeating character is f531
=
9First non-repeating character is f767
First non-repeating character is f27
First non-repeating character is f
7"geeksforgeeks"
3 First non-repeating character is f
299
First non-repeating character is f
First non-repeating character is f
215 =
"geeksforgeeks"
: O[N],
As the string needs to be traversed once
Auxiliary Space: O[1], Space is occupied by the use of count-array to keep track of frequency.
Nhân vật không lặp lại đầu tiên bằng cách sử dụng các hàm Python tích hợp:
Ý tưởng là tìm tần số của tất cả các ký tự trong chuỗi và kiểm tra ký tự nào có tần số đơn vị.unit frequency.
Thực hiện theo các bước dưới đây để giải quyết vấn đề:
- Tính tất cả các tần số của tất cả các ký tự bằng hàm bộ đếm [].
- Đi qua chuỗi và kiểm tra nếu bất kỳ phần tử nào có tần số 1.
- In ký tự và phá vỡ vòng lặp.
Dưới đây là việc thực hiện phương pháp trên:
Python3
First non-repeating character is f108
First non-repeating character is f109
First non-repeating character is f29
First non-repeating character is f111
First non-repeating character is f09
First non-repeating character is f113
First non-repeating character is f0
First non-repeating character is f115
=
First non-repeating character is f117
First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f7
First non-repeating character is f8
First non-repeating character is f9
Các
‘
=
5
First non-repeating character is f3
string
=
"geeksforgeeks"
First non-repeating character is f141
Đầu ra
First non-repeating character is f
Độ phức tạp về thời gian: O [N]. Vì chuỗi cần được đi qua ít nhất một lần. Không gian của bạn: O [256], không gian bị chiếm bởi việc sử dụng mảng tần số.O[N]. As the string needs to be traversed at least once.
Auxiliary Space: O[256], Space is occupied by the use of the frequency array.
Vấn đề liên quan: Nhân vật không lặp lại của K
Bài viết này được đóng góp bởi aarti_rathi. & Nbsp; vui lòng viết nhận xét nếu bạn tìm thấy bất cứ điều gì không chính xác hoặc bạn muốn chia sẻ thêm thông tin về chủ đề được thảo luận ở trên.Aarti_Rathi.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.