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
Java
First non-repeating character is f09
First non-repeating character is f10
First non-repeating character is f11
First non-repeating character is f12
First non-repeating character is f13
First non-repeating character is f14
First non-repeating character is f15
string
4 First non-repeating character is f17
First non-repeating character is f13
string
6First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f0
=
0 First non-repeating character is f24
First non-repeating character is f25
First non-repeating character is f26
First non-repeating character is f27
First non-repeating character is f1
First non-repeating character is f29
First non-repeating character is f2
First non-repeating character is f31
First non-repeating character is f2
First non-repeating character is f7
First non-repeating character is f35
=
9First non-repeating character is f37
First non-repeating character is f7
First non-repeating character is f3
"geeksforgeeks"
4First non-repeating character is f27
"geeksforgeeks"
6First non-repeating character is f0
"geeksforgeeks"
6First non-repeating character is f0
"geeksforgeeks"
3"geeksforgeeks"
4First non-repeating character is f13
"geeksforgeeks"
6First non-repeating character is f13
First non-repeating character is f14
First non-repeating character is f15
string
4 First non-repeating character is f54
First non-repeating character is f0
First non-repeating character is f56
"geeksforgeeks"
"geeksforgeeks"
4First non-repeating character is f0
First non-repeating character is f07
First non-repeating character is f13
"geeksforgeeks"
6"geeksforgeeks"
6
Python3
First non-repeating character is f64
First non-repeating character is f65
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 f70
First non-repeating character is f7
First non-repeating character is f1
First non-repeating character is f73
First non-repeating character is f9__12
=
5
First non-repeating character is f9
First non-repeating character is f0
First non-repeating character is f8
First non-repeating character is f86
=
5
First non-repeating character is f3
First non-repeating character is f0
"geeksforgeeks"
3First non-repeating character is f91
=
First non-repeating character is f93
First non-repeating character is f94
C#
string
1
First non-repeating character is f96
First non-repeating character is f14
First non-repeating character is f15
First non-repeating character is f11
First non-repeating character is f12
First non-repeating character is f0
First non-repeating character is f14
First non-repeating character is f15
string
4 First non-repeating character is f05
First non-repeating character is f06
First non-repeating character is f07
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 f14
=
5
First non-repeating character is f1
First non-repeating character is f17
First non-repeating character is f18
First non-repeating character is f19
First non-repeating character is f18
First non-repeating character is f21
First non-repeating character is f22
=
9First non-repeating character is f22
First non-repeating character is f25
First non-repeating character is f18
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 f39
First non-repeating character is f15
string
4 First non-repeating character is f42
First non-repeating character is f0
string
6First non-repeating character is f7
First non-repeating character is f06
First non-repeating character is f47
"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 f55
First non-repeating character is f56
First non-repeating character is f57
First non-repeating character is f58
First non-repeating character is f6
First non-repeating character is f60
First non-repeating character is f58
string
6First non-repeating character is f63
First non-repeating character is f1
First non-repeating character is f65
First non-repeating character is f63
string
6First non-repeating character is f68
First non-repeating character is f69
First non-repeating character is f68
First non-repeating character is f3
First non-repeating character is f63
"geeksforgeeks"
6First non-repeating character is f58
"geeksforgeeks"
6First non-repeating character is f58
"geeksforgeeks"
3"geeksforgeeks"
6
First non-repeating character is f79
First non-repeating character is f93
First non-repeating character is f94
First non-repeating character is f82
Đầ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.
Thực hiện theo các bước dưới đây để giải quyết vấn đề:
- Tạo một hash_map sẽ ánh xạ ký tự theo tần số tương ứng của chúng.hash_map that will map the character to their respective frequencies.
- Traverse Chuỗi đã cho bằng một con trỏ.
- Tăng số lượng của ký tự hiện tại trong Hash_Map.hash_map.
- Bây giờ hãy đi qua chuỗi một lần nữa và kiểm tra xem ký tự hiện tại HasFrequency = 1.frequency=1.
- Nếu tần số> 1 tiếp tục truyền tải.frequency>1 continue the traversal.
- Khác phá vỡ vòng lặp và in ký tự hiện tại là câu trả lời.break the loop and print the current character as the answer.
Dưới đây là việc thực hiện phương pháp trên.
C++
First non-repeating character is f83
string
1 string
2 string
3
First non-repeating character is f87
=
0
First non-repeating character is f89
First non-repeating character is f90
First non-repeating character is f91
string
6
First non-repeating character is f0
=
0First non-repeating character is f95
=
0First non-repeating character is f97
First non-repeating character is f98
First non-repeating character is f0
First non-repeating character is f00
First non-repeating character is f0
=
0First non-repeating character is f03
First non-repeating character is f0
=
0 First non-repeating character is f06
First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f09
First non-repeating character is f7
First non-repeating character is f11
First non-repeating character is f0
"geeksforgeeks"
3 First non-repeating character is f14
"geeksforgeeks"
6
=
0
First non-repeating character is f17
First non-repeating character is f90
First non-repeating character is f91
string
6
First non-repeating character is f0
=
0First non-repeating character is f23
First non-repeating character is f0
=
0 First non-repeating character is f26
First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f29
First non-repeating character is f7
First non-repeating character is f1
First non-repeating character is f32
=
5
First non-repeating character is f34
=
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 f43
First non-repeating character is f44
First non-repeating character is f0
"geeksforgeeks"
3 First non-repeating character is f47
"geeksforgeeks"
6
=
0
First non-repeating character is f00
string
6
First non-repeating character is f0
First non-repeating character is f90
First non-repeating character is f54
"geeksforgeeks"
"geeksforgeeks"
4First non-repeating character is f0
=
0 First non-repeating character is f59
First non-repeating character is f0
First non-repeating character is f1
First non-repeating character is f62
First non-repeating character is f7
=
8index
1First non-repeating character is f18
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 f74
First non-repeating character is f75
First non-repeating character is f0
First non-repeating character is f77
First non-repeating character is f78
First non-repeating character is f0
"geeksforgeeks"
3 First non-repeating character is f81
"geeksforgeeks"
6
C
First non-repeating character is f83
First non-repeating character is f84
First non-repeating character is f87
=
0
First non-repeating character is f89
First non-repeating character is f90
First non-repeating character is f91
string
6
First non-repeating character is f0
=
0First non-repeating character is f95
=
0First non-repeating character is f97
First non-repeating character is f98
First non-repeating character is f0
First non-repeating character is f00
First non-repeating character is f0
=
0First non-repeating character is f03
First non-repeating character is f0
=
0 First non-repeating character is f06
First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f09
First non-repeating character is f7
First non-repeating character is f11
First non-repeating character is f0
"geeksforgeeks"
3 First non-repeating character is f14
"geeksforgeeks"
6
=
0
First non-repeating character is f17
First non-repeating character is f90
First non-repeating character is f91
string
6
First non-repeating character is f0
=
0First non-repeating character is f23
First non-repeating character is f0
=
0 First non-repeating character is f26
First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f29
First non-repeating character is f7
First non-repeating character is f1
First non-repeating character is f32
=
5
First non-repeating character is f34
=
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 f43
First non-repeating character is f44
First non-repeating character is f0
"geeksforgeeks"
3 First non-repeating character is f47
"geeksforgeeks"
6
=
0
First non-repeating character is f00
string
6
First non-repeating character is f0
First non-repeating character is f90
First non-repeating character is f54
"geeksforgeeks"
"geeksforgeeks"
4First non-repeating character is f0
=
0 First non-repeating character is f59
First non-repeating character is f0
First non-repeating character is f1
First non-repeating character is f62
First non-repeating character is f7
First non-repeating character is f62
First non-repeating character is f0
index
1First non-repeating character is f65
index
3First non-repeating character is f67
First non-repeating character is f0
First non-repeating character is f5
First non-repeating character is f7
First non-repeating character is f62
First non-repeating character is f0
First non-repeating character is f73
First non-repeating character is f74
First non-repeating character is f65
First non-repeating character is f76
First non-repeating character is f0
"geeksforgeeks"
3 First non-repeating character is f81
First non-repeating character is f0
"geeksforgeeks"
3 First non-repeating character is f81
"geeksforgeeks"
6
C
First non-repeating character is f83
First non-repeating character is f0
First non-repeating character is f777
First non-repeating character is f78
Java
First non-repeating character is f09
First non-repeating character is f85
First non-repeating character is f11
First non-repeating character is f12
First non-repeating character is f0
string
6First non-repeating character is f0
First non-repeating character is f15
First non-repeating character is f90
=
0 First non-repeating character is f92
First non-repeating character is f93
"geeksforgeeks"
4=
5
First non-repeating character is f16
First non-repeating character is f0
"geeksforgeeks"
6First non-repeating character is f0
First non-repeating character is f15
First non-repeating character is f90
First non-repeating character is f98
First non-repeating character is f99
First non-repeating character is f90
First non-repeating character is f01
First non-repeating character is f0
First non-repeating character is f15
string
4 First non-repeating character is f05
First non-repeating character is f7
First non-repeating character is f26
First non-repeating character is f7
First non-repeating character is f6
First non-repeating character is f0
=
0 First non-repeating character is f24
First non-repeating character is f25
First non-repeating character is f14
First non-repeating character is f0
First non-repeating character is f15
=
0 First non-repeating character is f22
First non-repeating character is f0
string
6First non-repeating character is f18
First non-repeating character is f34
First non-repeating character is f18
First non-repeating character is f3
"geeksforgeeks"
4=
5"geeksforgeeks"
6
First non-repeating character is f7
"geeksforgeeks"
6First non-repeating character is f7
=
0 First non-repeating character is f29
First non-repeating character is f2
First non-repeating character is f31
First non-repeating character is f0
"geeksforgeeks"
6First non-repeating character is f7
First non-repeating character is f6
First non-repeating character is f34
First non-repeating character is f25
First non-repeating character is f36
First non-repeating character is f0
string
6First non-repeating character is f7
First non-repeating character is f64
"geeksforgeeks"
"geeksforgeeks"
4=
5
First non-repeating character is f1
First non-repeating character is f39
First non-repeating character is f2
First non-repeating character is f33
First non-repeating character is f7
First non-repeating character is f35
First non-repeating character is f7
"geeksforgeeks"
3 First non-repeating character is f47
First non-repeating character is f18
First non-repeating character is f76
First non-repeating character is f77
First non-repeating character is f78
First non-repeating character is f79
First non-repeating character is f80
First non-repeating character is f18
First non-repeating character is f82
=
9First non-repeating character is f78
First non-repeating character is f85
First non-repeating character is f0
"geeksforgeeks"
6"geeksforgeeks"
6
Python3
First non-repeating character is f0
First non-repeating character is f14
First non-repeating character is f15
string
4 First non-repeating character is f60
First non-repeating character is f7
=
0 First non-repeating character is f59
=
5
First non-repeating character is f73
First non-repeating character is f2
First non-repeating character is f89
=
First non-repeating character is f93
First non-repeating character is f64
First non-repeating character is f93
Các
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
string
08string
09string
10First non-repeating character is f9
=
First non-repeating character is f0
"geeksforgeeks"
3 string
16First non-repeating character is f64
string
18First non-repeating character is f89
=
First non-repeating character is f93
First non-repeating character is f64
First non-repeating character is f93
Các
=
5
First non-repeating character is f3
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
string
08string
09string
10First non-repeating character is f9
=
First non-repeating character is f0
"geeksforgeeks"
3 string
16First non-repeating character is f64
string
18First 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
string
83C#
string
1
First non-repeating character is f96
string
1 string
87
First non-repeating character is f11
First non-repeating character is f12
First non-repeating character is f0
First non-repeating character is f15
=
0 string
93First non-repeating character is f0
First non-repeating character is f15
First non-repeating character is f90
string
97First non-repeating character is f99
First non-repeating character is f90
First non-repeating character is f01
First non-repeating character is f0
First non-repeating character is f15
string
4 =
04First non-repeating character is f06
=
06
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 =
13=
5=
15
First non-repeating character is f0
"geeksforgeeks"
6First non-repeating character is f0
First non-repeating character is f15
=
0 First non-repeating character is f17
First non-repeating character is f06
=
06First non-repeating character is f0
string
6First non-repeating character is f7
First non-repeating character is f26
First non-repeating character is f7
=
0 First non-repeating character is f26
First non-repeating character is f7
First non-repeating character is f6
=
33=
5
First non-repeating character is f1
=
36First non-repeating character is f18
First non-repeating character is f34
First non-repeating character is f18
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 f47
First non-repeating character is f0
"geeksforgeeks"
6First non-repeating character is f0
First non-repeating character is f14
First non-repeating character is f15
string
4 First non-repeating character is f42
First non-repeating character is f0
string
6First non-repeating character is f7
First non-repeating character is f06
=
60"geeksforgeeks"
"geeksforgeeks"
4First non-repeating character is f7
=
0 First non-repeating character is f59
First non-repeating character is f7
=
67=
5=
69
First non-repeating character is f18
First non-repeating character is f76
=
72First non-repeating character is f78
First non-repeating character is f79
=
75First non-repeating character is f78
First non-repeating character is f79
First non-repeating character is f80
First non-repeating character is f18
First non-repeating character is f82
=
81First non-repeating character is f78
First non-repeating character is f79
=
84 =
85First non-repeating character is f0
"geeksforgeeks"
6"geeksforgeeks"
6
PHP
=
89
=
90 =
91
‘
First non-repeating character is f56
=
04=
98First non-repeating character is f2
string
6
First non-repeating character is f0
"geeksforgeeks"
02 =
92"geeksforgeeks"
4First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f0
"geeksforgeeks"
08 "geeksforgeeks"
09"geeksforgeeks"
10"geeksforgeeks"
08 "geeksforgeeks"
12"geeksforgeeks"
13
First non-repeating character is f0
=
98"geeksforgeeks"
16"geeksforgeeks"
08"geeksforgeeks"
18First non-repeating character is f7
=
92"geeksforgeeks"
21=
98First non-repeating character is f97
"geeksforgeeks"
08"geeksforgeeks"
25"geeksforgeeks"
6
First non-repeating character is f56
First non-repeating character is f17
=
98First non-repeating character is f2
string
6
First non-repeating character is f0
"geeksforgeeks"
02 =
92"geeksforgeeks"
4First non-repeating character is f0
=
04=
98First non-repeating character is f67
First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f0
"geeksforgeeks"
08 "geeksforgeeks"
09First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f0
"geeksforgeeks"
08 "geeksforgeeks"
09"geeksforgeeks"
10"geeksforgeeks"
08 "geeksforgeeks"
12"geeksforgeeks"
13
First non-repeating character is f0
=
98"geeksforgeeks"
16"geeksforgeeks"
08"geeksforgeeks"
18First non-repeating character is f0
string
6First non-repeating character is f56
First non-repeating character is f17
=
98First non-repeating character is f2
First non-repeating character is f7
string
6First non-repeating character is f0
"geeksforgeeks"
41 "geeksforgeeks"
42=
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 f7
First non-repeating character is f1
First non-repeating character is f0
=
92"geeksforgeeks"
21=
98First non-repeating character is f97
"geeksforgeeks"
08"geeksforgeeks"
67"geeksforgeeks"
6
=
5"geeksforgeeks"
41 "geeksforgeeks"
72"geeksforgeeks"
08"geeksforgeeks"
4
"geeksforgeeks"
3 "geeksforgeeks"
41"geeksforgeeks"
4
=
98 "geeksforgeeks"
72"geeksforgeeks"
"geeksforgeeks"
4
"geeksforgeeks"
41 "geeksforgeeks"
91=
98
First non-repeating character is f67
index
01index
02"geeksforgeeks"
4
First non-repeating character is f5
First non-repeating character is f1
First non-repeating character is f0
"geeksforgeeks"
41 "geeksforgeeks"
97=
5index
09index
00
First non-repeating character is f65
=
98First non-repeating character is f97
"geeksforgeeks"
41index
15index
16
"geeksforgeeks"
98 "geeksforgeeks"
99 index
00
First non-repeating character is f
"geeksforgeeks"
98 index
06index
00O[N], Traversing over the string of size N
Auxiliary Space: O[256], To store the frequency of the characters in the string.
Đầu raHashMap and single string traversal
Độ 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 đơn
- Ý 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 which will have two fields namely frequency, first occurrence of a character.
- Thực hiện theo các bước dưới đây để giải quyết vấn đề:count_array is 256.
- 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ỏ.
- Tăng số lượng các ký tự hiện tại và cập nhật sự xuất hiện.count_array[] and find the character with the least first occurrence value and frequency value as unity.
- 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.
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.
C++
string
0
Trả lại nhân vật đó.
First non-repeating character is f87
Dưới đây là việc thực hiện phương pháp trên.
string
6
First non-repeating character is f0
index
28=
0index
30=
0index
32string
1 string
2 string
3
First non-repeating character is f7
index
39First non-repeating character is f7
index
41First non-repeating character is f0
"geeksforgeeks"
6=
0
First non-repeating character is f17
First non-repeating character is f90
First non-repeating character is f91
First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f0
=
0 index
37First non-repeating character is f0
=
0 index
46=
5index
56
First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f0
=
0 index
51"geeksforgeeks"
6
First non-repeating character is f7
First non-repeating character is f1
index
54string
6
First non-repeating character is f0
"geeksforgeeks"
3 index
59=
0
First non-repeating character is f00
First non-repeating character is f0
First non-repeating character is f90
First non-repeating character is f54
"geeksforgeeks"
"geeksforgeeks"
4First non-repeating character is f7
First non-repeating character is f62
First non-repeating character is f0
index
78First non-repeating character is f65
index
80First non-repeating character is f67
First non-repeating character is f0
First non-repeating character is f5
First non-repeating character is f7
First non-repeating character is f62
First non-repeating character is f0
=
81First non-repeating character is f65
index
89First non-repeating character is f74
First non-repeating character is f65
First non-repeating character is f76
First non-repeating character is f0
"geeksforgeeks"
3 First non-repeating character is f81
"geeksforgeeks"
6
C
index
97
First non-repeating character is f83
First non-repeating character is f84
First non-repeating character is f87
First non-repeating character is f001
First non-repeating character is f002
First non-repeating character is f0
=
0 First non-repeating character is f14
First non-repeating character is f0
=
0 First non-repeating character is f47
First non-repeating character is f009
First non-repeating character is f001
First non-repeating character is f011
First non-repeating character is f90
First non-repeating character is f91
string
6
First non-repeating character is f0
First non-repeating character is f001
First non-repeating character is f017
First non-repeating character is f001
First non-repeating character is f019
First non-repeating character is f98
First non-repeating character is f0
First non-repeating character is f7
First non-repeating character is f00
First non-repeating character is f0
First non-repeating character is f001
First non-repeating character is f026
First non-repeating character is f0
=
0 First non-repeating character is f06
First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f29
First non-repeating character is f7
First non-repeating character is f034
First non-repeating character is f7
First non-repeating character is f1
First non-repeating character is f037
=
5
First non-repeating character is f039
First non-repeating character is f0
"geeksforgeeks"
6First non-repeating character is f0
"geeksforgeeks"
3 First non-repeating character is f14
"geeksforgeeks"
6
=
0
First non-repeating character is f17
First non-repeating character is f90
First non-repeating character is f91
string
6
First non-repeating character is f0
First non-repeating character is f001
First non-repeating character is f053
First non-repeating character is f0
=
0 First non-repeating character is f056
First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f059
First non-repeating character is f7
First non-repeating character is f1
First non-repeating character is f062
=
5
First non-repeating character is f064
First non-repeating character is f0
"geeksforgeeks"
6First non-repeating character is f0
First non-repeating character is f43
First non-repeating character is f44
First non-repeating character is f0
"geeksforgeeks"
3 First non-repeating character is f072
"geeksforgeeks"
6
=
0
First non-repeating character is f00
string
6
First non-repeating character is f0
First non-repeating character is f90
First non-repeating character is f54
"geeksforgeeks"
"geeksforgeeks"
4First non-repeating character is f0
=
0 First non-repeating character is f59
First non-repeating character is f0
First non-repeating character is f1
index
74First non-repeating character is f7
First non-repeating character is f62
First non-repeating character is f0
"geeksforgeeks"
99First non-repeating character is f65
index
02First non-repeating character is f67
First non-repeating character is f0
First non-repeating character is f5
First non-repeating character is f7
First non-repeating character is f62
First non-repeating character is f0
=
81First non-repeating character is f65
index
89First non-repeating character is f74
First non-repeating character is f65
First non-repeating character is f76
First non-repeating character is f0
First non-repeating character is f77
First non-repeating character is f78
First non-repeating character is f0
"geeksforgeeks"
3 First non-repeating character is f81
"geeksforgeeks"
6
Java
First non-repeating character is f09
First non-repeating character is f10
First non-repeating character is f11
First non-repeating character is f116
First non-repeating character is f0
=
0 First non-repeating character is f119
First non-repeating character is f0
First non-repeating character is f14
First non-repeating character is f12222222
First non-repeating character is f124
First non-repeating character is f0
string
6First non-repeating character is f7
First non-repeating character is f128
First non-repeating character is f129
First non-repeating character is f2
"geeksforgeeks"
4First non-repeating character is f7
First non-repeating character is f128
First non-repeating character is f134
First non-repeating character is f0
"geeksforgeeks"
6First non-repeating character is f0
First non-repeating character is f14
string
4 First non-repeating character is f140
First non-repeating character is f128
First non-repeating character is f142
"geeksforgeeks"
6
First non-repeating character is f11
First non-repeating character is f12
First non-repeating character is f0
First non-repeating character is f15
First non-repeating character is f90
=
0 First non-repeating character is f92
First non-repeating character is f93
"geeksforgeeks"
4First non-repeating character is f0
First non-repeating character is f15
First non-repeating character is f155
First non-repeating character is f7
"geeksforgeeks"
72First non-repeating character is f99
First non-repeating character is f159
First non-repeating character is f0
First non-repeating character is f15
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 f6
First non-repeating character is f0
=
0 First non-repeating character is f24
First non-repeating character is f25
First non-repeating character is f36
=
5
First non-repeating character is f1
First non-repeating character is f175
First non-repeating character is f18
First non-repeating character is f177
=
5"geeksforgeeks"
6
=
5
First non-repeating character is f5
string
6First non-repeating character is f18
First non-repeating character is f184
First non-repeating character is f99
First non-repeating character is f186
=
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 f15
=
0 First non-repeating character is f22
First non-repeating character is f0
string
6First non-repeating character is f7
First non-repeating character is f26
First non-repeating character is f7
=
0 First non-repeating character is f203
First non-repeating character is f7
First non-repeating character is f6
First non-repeating character is f206
First non-repeating character is f74
First non-repeating character is f208
=
5=
0
First non-repeating character is f211
=
5=
0
First non-repeating character is f214
=
5
First non-repeating character is f1
First non-repeating character is f217
First non-repeating character is f2
First non-repeating character is f219
First non-repeating character is f18
First non-repeating character is f221
=
5"geeksforgeeks"
6
First non-repeating character is f7
"geeksforgeeks"
6First non-repeating character is f7
"geeksforgeeks"
3 First non-repeating character is f072
First non-repeating character is f0
"geeksforgeeks"
6First non-repeating character is f0
First non-repeating character is f14
First non-repeating character is f15
string
4 First non-repeating character is f60
First non-repeating character is f0
string
6First non-repeating character is f7
First non-repeating character is f64
"geeksforgeeks"
"geeksforgeeks"
4First non-repeating character is f7
=
0 First non-repeating character is f59
First non-repeating character is f7
First non-repeating character is f35
=
5
First non-repeating character is f248
First non-repeating character is f18
First non-repeating character is f76
First non-repeating character is f251
First non-repeating character is f78
First non-repeating character is f79
First non-repeating character is f254
First non-repeating character is f18
First non-repeating character is f82
=
9First non-repeating character is f78
First non-repeating character is f85
First non-repeating character is f0
"geeksforgeeks"
6"geeksforgeeks"
6
Python3
First non-repeating character is f09
First non-repeating character is f264
First non-repeating character is f89
=
First non-repeating character is f93
First non-repeating character is f64
First non-repeating character is f17
First non-repeating character is f270
First non-repeating character is f271
First non-repeating character is f0
First non-repeating character is f273
=
First non-repeating character is f275
First non-repeating character is f6
First non-repeating character is f7__
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 f279
First non-repeating character is f286
First non-repeating character is f7
First non-repeating character is f288
=
First non-repeating character is f97
First non-repeating character is f25
index
30__125First non-repeating character is f294
First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f7__18
Các
Các
First non-repeating character is f0
First non-repeating character is f327
=
First non-repeating character is f329
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 f279
First non-repeating character is f286
First non-repeating character is f7
First non-repeating character is f288
=
First non-repeating character is f97
First non-repeating character is f25
index
30__125First non-repeating character is f294
First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f7__18
Các
Các
First non-repeating character is f0
First non-repeating character is f327
=
First non-repeating character is f329
First non-repeating character is f7
First non-repeating character is f1
First non-repeating character is f338
First non-repeating character is f25
First non-repeating character is f93
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
=
9index
30First non-repeating character is f270
First non-repeating character is f381
C#
‘
First non-repeating character is f0
"geeksforgeeks"
3 First non-repeating character is f354
First non-repeating character is f11
First non-repeating character is f116
First non-repeating character is f0
=
0 First non-repeating character is f119
First non-repeating character is f0
First non-repeating character is f14
First non-repeating character is f12222
First non-repeating character is f124
First non-repeating character is f0
string
6First non-repeating character is f7
First non-repeating character is f128
First non-repeating character is f401
First non-repeating character is f7
First non-repeating character is f128
First non-repeating character is f134
First non-repeating character is f0
"geeksforgeeks"
6First non-repeating character is f0
First non-repeating character is f14
First non-repeating character is f409
string
4 First non-repeating character is f140
First non-repeating character is f128
First non-repeating character is f142
"geeksforgeeks"
6
First non-repeating character is f11
First non-repeating character is f12
First non-repeating character is f0
First non-repeating character is f14
First non-repeating character is f419
=
0 string
93First non-repeating character is f0
First non-repeating character is f14
First non-repeating character is f15
First non-repeating character is f425
First non-repeating character is f90
First non-repeating character is f427
First non-repeating character is f7
"geeksforgeeks"
72First non-repeating character is f99
First non-repeating character is f425
First non-repeating character is f90
First non-repeating character is f433
First non-repeating character is f0
First non-repeating character is f14
First non-repeating character is f15
string
4 =
04First non-repeating character is f06
=
06First 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 f447
=
5
First non-repeating character is f1
First non-repeating character is f450
First non-repeating character is f18
First non-repeating character is f452
=
5"geeksforgeeks"
6
=
5
First non-repeating character is f5
string
6First non-repeating character is f18
First non-repeating character is f459
First non-repeating character is f99
First non-repeating character is f461
=
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 f39
First non-repeating character is f15
=
0 First non-repeating character is f17
First non-repeating character is f06
=
06First non-repeating character is f0
string
6First non-repeating character is f7
First non-repeating character is f26
First non-repeating character is f7
=
0 First non-repeating character is f481
=
0First non-repeating character is f483
First non-repeating character is f7
First non-repeating character is f6
=
33=
5
First non-repeating character is f1
First non-repeating character is f489
First non-repeating character is f18
First non-repeating character is f491
First non-repeating character is f18
First non-repeating character is f493
=
5"geeksforgeeks"
6
First non-repeating character is f7
"geeksforgeeks"
6First non-repeating character is f7
"geeksforgeeks"
3 First non-repeating character is f072
First non-repeating character is f0
"geeksforgeeks"
6First non-repeating character is f0
First non-repeating character is f14
First non-repeating character is f15
string
4 First non-repeating character is f507
First non-repeating character is f06
First non-repeating character is f509
First non-repeating character is f0
string
6First non-repeating character is f7
First non-repeating character is f06
=
60"geeksforgeeks"
"geeksforgeeks"
4First non-repeating character is f7
=
0 First non-repeating character is f59
First non-repeating character is f7
=
67=
5
First non-repeating character is f523
=
0First non-repeating character is f525
First non-repeating character is f18
First non-repeating character is f76
First non-repeating character is f251
First non-repeating character is f78
First non-repeating character is f79
First non-repeating character is f254
First non-repeating character is f18
First non-repeating character is f82
=
9First non-repeating character is f78
=
85First non-repeating character is f0
"geeksforgeeks"
6"geeksforgeeks"
6
JavaScript
First non-repeating character is f55
First non-repeating character is f541
First non-repeating character is f56
First non-repeating character is f543
string
6
First non-repeating character is f0
First non-repeating character is f546
First non-repeating character is f99
First non-repeating character is f548
First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f551
First non-repeating character is f7
First non-repeating character is f553
First non-repeating character is f0
"geeksforgeeks"
6First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f558
First non-repeating character is f7
First non-repeating character is f560
First non-repeating character is f7
First non-repeating character is f562
First non-repeating character is f0
"geeksforgeeks"
6First non-repeating character is f0
First non-repeating character is f566
First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f569
First non-repeating character is f7
First non-repeating character is f1
First non-repeating character is f572
=
5
First non-repeating character is f574
First non-repeating character is f0
"geeksforgeeks"
3 index
59"geeksforgeeks"
6
First non-repeating character is f579
"geeksforgeeks"
"geeksforgeeks"
4First non-repeating character is f582
First non-repeating character is f1
First non-repeating character is f584
First non-repeating character is f0
First non-repeating character is f586
First non-repeating character is f1
First non-repeating character is f67
First non-repeating character is f5
First non-repeating character is f0
First non-repeating character is f586
=
9First non-repeating character is f593
First non-repeating character is f82
Đầ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 f595
First non-repeating character is f83
string
1 string
2 string
3
=
0
First non-repeating character is f601
string
6
First non-repeating character is f0
=
0 First non-repeating character is f605
First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f0
=
0 First non-repeating character is f610
First non-repeating character is f7
First non-repeating character is f612
First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f0
=
0 First non-repeating character is f617
First non-repeating character is f7
First non-repeating character is f1
First non-repeating character is f620
=
5
First non-repeating character is f622
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 f629
First non-repeating character is f7
"geeksforgeeks"
6First non-repeating character is f0
"geeksforgeeks"
6First non-repeating character is f0
=
0 index
46First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f0
=
0 First non-repeating character is f641
First non-repeating character is f7
First non-repeating character is f1
First non-repeating character is f644
=
5
First non-repeating character is f646
First non-repeating character is f0
"geeksforgeeks"
6First non-repeating character is f0____21
First non-repeating character is f651
First non-repeating character is f7
"geeksforgeeks"
3 First non-repeating character is f654
First non-repeating character is f0
First non-repeating character is f5
First non-repeating character is f7
"geeksforgeeks"
3 index
59"geeksforgeeks"
6
=
0
First non-repeating character is f00
string
6
First non-repeating character is f0
First non-repeating character is f665
First non-repeating character is f0
=
60"geeksforgeeks"
"geeksforgeeks"
4First non-repeating character is f0
=
0 First non-repeating character is f672
First non-repeating character is f0____21
First non-repeating character is f675
First non-repeating character is f7
=
8index
1First non-repeating character is f18
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 f74
First non-repeating character is f688
First non-repeating character is f0
"geeksforgeeks"
3 First non-repeating character is f81
"geeksforgeeks"
6
Java
First non-repeating character is f14
First non-repeating character is f11
First non-repeating character is f12
First non-repeating character is f0
First non-repeating character is f14
First non-repeating character is f15
=
0 First non-repeating character is f22
First non-repeating character is f0
string
6First non-repeating character is f7
=
0First non-repeating character is f705
=
5"geeksforgeeks"
72
First non-repeating character is f99
=
0First non-repeating character is f97
First non-repeating character is f93
First non-repeating character is f712
First non-repeating character is f7
First non-repeating character is f6
First non-repeating character is f0
=
0 First non-repeating character is f24
First non-repeating character is f25
First non-repeating character is f719
First non-repeating character is f93
First non-repeating character is f721
=
5
First non-repeating character is f723
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 f24
First non-repeating character is f25
First non-repeating character is f36
=
5
First non-repeating character is f1
First non-repeating character is f735
First non-repeating character is f2
First non-repeating character is f33
First non-repeating character is f18
First non-repeating character is f739
=
5"geeksforgeeks"
6
=
5
First non-repeating character is f5
string
6
First non-repeating character is f18
First non-repeating character is f746
First non-repeating character is f747
"geeksforgeeks"
4=
5"geeksforgeeks"
6
First non-repeating character is f7
"geeksforgeeks"
6First non-repeating character is f7
=
0 First non-repeating character is f755
First non-repeating character is f7
First non-repeating character is f6
First non-repeating character is f0
=
0 First non-repeating character is f24
First non-repeating character is f25
First non-repeating character is f719
First non-repeating character is f93
First non-repeating character is f764
=
5
First non-repeating character is f1
First non-repeating character is f767
First non-repeating character is f25
First non-repeating character is f2
First non-repeating character is f18
First non-repeating character is f771
First non-repeating character is f7
"geeksforgeeks"
6First non-repeating character is f7
First non-repeating character is f1
First non-repeating character is f776
=
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
59
First non-repeating character is f0
"geeksforgeeks"
6First non-repeating character is f0
First non-repeating character is f14
First non-repeating character is f15
string
4 First non-repeating character is f793
First non-repeating character is f0
string
6First non-repeating character is f7
First non-repeating character is f797
First non-repeating character is f7
=
60"geeksforgeeks"
"geeksforgeeks"
4First non-repeating character is f7
=
0 First non-repeating character is f672
First non-repeating character is f7
First non-repeating character is f1
First non-repeating character is f807
First non-repeating character is f2
First non-repeating character is f2
=
5
First non-repeating character is f35
First non-repeating character is f18
First non-repeating character is f1
First non-repeating character is f67
First non-repeating character is f7
First non-repeating character is f5
=
5
First non-repeating character is f35
First non-repeating character is f18
=
9First non-repeating character is f18
First non-repeating character is f822
First non-repeating character is f0
"geeksforgeeks"
6"geeksforgeeks"
6
Python3
First non-repeating character is f09
First non-repeating character is f264
First non-repeating character is f64
First non-repeating character is f17
First non-repeating character is f270
First non-repeating character is f271
First non-repeating character is f0
First non-repeating character is f833
=
First non-repeating character is f97___
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 f279
First non-repeating character is f0
First non-repeating character is f301
First non-repeating character is f0
First non-repeating character is f270
First non-repeating character is f304
Các
=
5
First non-repeating character is f868
string
09First non-repeating character is f0__
First non-repeating character is f7
First non-repeating character is f5
First non-repeating character is f6
=
5
First non-repeating character is f868
string
09First non-repeating character is f0__
First non-repeating character is f0
First non-repeating character is f327
=
First non-repeating character is f329
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 f279
First non-repeating character is f0
First non-repeating character is f93
First non-repeating character is f271
First non-repeating character is f7
First non-repeating character is f1
First non-repeating character is f901
=
First non-repeating character is f25
First non-repeating character is f271
=
5
First non-repeating character is f327
=
First non-repeating character is f348
First non-repeating character is f909
First non-repeating character is f0
First non-repeating character is f1
First non-repeating character is f912
=
__ First non-repeating character is f367
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 f354
First non-repeating character is f270
=
"geeksforgeeks"
First non-repeating character is f929
=
First non-repeating character is f17
First non-repeating character is f270
First non-repeating character is f2
First non-repeating character is f1
First non-repeating character is f935
=
__ First non-repeating character is f1
First non-repeating character is f2
First non-repeating character is f271
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 f953
First non-repeating character is f0
First non-repeating character is f270
First non-repeating character is f956
C#
string
1
First non-repeating character is f96
First non-repeating character is f14
First non-repeating character is f11
First non-repeating character is f12
First non-repeating character is f0
First non-repeating character is f14
First non-repeating character is f15
=
0 First non-repeating character is f17
First non-repeating character is f06
=
06First non-repeating character is f0
string
6First non-repeating character is f7
=
0First non-repeating character is f705
=
5"geeksforgeeks"
72
First non-repeating character is f99
=
0First non-repeating character is f978
First non-repeating character is f7
First non-repeating character is f6
First non-repeating character is f0
=
0 First non-repeating character is f610
=
5
First non-repeating character is f612
First non-repeating character is f7
First non-repeating character is f6
First non-repeating character is f0
=
0 First non-repeating character is f447
=
5
First non-repeating character is f1
First non-repeating character is f620
First non-repeating character is f18
First non-repeating character is f622
=
5"geeksforgeeks"
6
=
5
First non-repeating character is f5
string
6First non-repeating character is f18
First non-repeating character is f629
=
5"geeksforgeeks"
6
First non-repeating character is f7
"geeksforgeeks"
6First non-repeating character is f7
=
0 First non-repeating character is f755
First non-repeating character is f7
First non-repeating character is f6
First non-repeating character is f0
=
0 First non-repeating character is f24
First non-repeating character is f25
First non-repeating character is f719
First non-repeating character is f93
First non-repeating character is f764
=
5
First non-repeating character is f1
First non-repeating character is f767
First non-repeating character is f25
First non-repeating character is f2
First non-repeating character is f18
First non-repeating character is f019
First non-repeating character is f7
"geeksforgeeks"
6First non-repeating character is f7
First non-repeating character is f1
First non-repeating character is f776
=
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
59
First non-repeating character is f0
"geeksforgeeks"
6First non-repeating character is f0
First non-repeating character is f14
First non-repeating character is f15
string
4 First non-repeating character is f793
First non-repeating character is f0
string
6First non-repeating character is f7
=
0 First non-repeating character is f672
First non-repeating character is f7
=
60"geeksforgeeks"
"geeksforgeeks"
4First non-repeating character is f7
=
0 First non-repeating character is f672
First non-repeating character is f7
First non-repeating character is f1
First non-repeating character is f807
First non-repeating character is f2
First non-repeating character is f2
=
5=
67
First non-repeating character is f18
First non-repeating character is f1
First non-repeating character is f67
First non-repeating character is f7
First non-repeating character is f5
=
5=
67
First non-repeating character is f18
=
9First non-repeating character is f18
First non-repeating character is f067
First non-repeating character is f0
"geeksforgeeks"
6"geeksforgeeks"
6
First non-repeating character is f
09 First non-repeating character is f
264
First non-repeating character is f55
First non-repeating character is f64
First non-repeating character is f17
First non-repeating character is f270
First non-repeating character is f271
string
6
First non-repeating character is f0
First non-repeating character is f833
=
First non-repeating character is f97___
First non-repeating character is f0
First non-repeating character is f081
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 f279
First non-repeating character is f0
First non-repeating character is f301
First non-repeating character is f0
First non-repeating character is f270
First non-repeating character is f304
First non-repeating character is f7
First non-repeating character is f612
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 f098
First non-repeating character is f7
string
6=
5
First non-repeating character is f102
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 f110
First non-repeating character is f7
"geeksforgeeks"
6First non-repeating character is f0
"geeksforgeeks"
6=
5
First non-repeating character is f868
string
09First non-repeating character is f0__
First non-repeating character is f0
First non-repeating character is f6
First non-repeating character is f0
First non-repeating character is f076
First non-repeating character is f122
First non-repeating character is f7
First non-repeating character is f1
First non-repeating character is f644
=
5
First non-repeating character is f771
First non-repeating character is f0
"geeksforgeeks"
6First non-repeating character is f0
First non-repeating character is f1
First non-repeating character is f132
"geeksforgeeks"
3 First non-repeating character is f654
First non-repeating character is f0
First non-repeating character is f5
"geeksforgeeks"
3 index
59"geeksforgeeks"
6
First non-repeating character is f076
First non-repeating character is f044
First non-repeating character is f0
=
60"geeksforgeeks"
"geeksforgeeks"
4First non-repeating character is f0
First non-repeating character is f076
First non-repeating character is f672
First non-repeating character is f0____21
First non-repeating character is f151
First non-repeating character is f7
First non-repeating character is f586
First non-repeating character is f1
First non-repeating character is f67
First non-repeating character is f0
First non-repeating character is f5
First non-repeating character is f7
First non-repeating character is f586
=
9First non-repeating character is f822
First non-repeating character is f82
Đầu ra
First non-repeating character is f
Độ phức tạp về thời gian: O [n], vì chuỗi cần phải đi qua không gian onceauxiliary: O [1], không gian bị chiếm bởi việc sử dụng số lượng đếm để theo dõi tần số.: 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 f163
First non-repeating character is f164
First non-repeating character is f09
First non-repeating character is f166
First non-repeating character is f64
First non-repeating character is f168
First non-repeating character is f0
First non-repeating character is f170
=
First non-repeating character is f172
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 f196
Đầu ra
First non-repeating character is f
Độ phức tạp về thời gian: O [n], vì chuỗi cần phải đi qua không gian onceauxiliary: O [1], không gian bị chiếm bởi việc sử dụng số lượng đếm để 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 the frequency array.
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ị.Aarti_Rathi.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.