Hướng dẫn first non repeating character in a string in c++ - ký tự không lặp lại đầu tiên trong một chuỗi trong c ++

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.

Hướng dẫn first non repeating character in a string in c++ - ký tự không lặp lại đầu tiên trong một chuỗi trong c ++

Đầ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 f
1
First non-repeating character is f
2

First non-repeating character is f
3=
First non-repeating character is f
5

First non-repeating character is f
6
First non-repeating character is f
7
First non-repeating character is f
8
First non-repeating character is f
9

First non-repeating character is f
0____21
First non-repeating character is f
2==
First non-repeating character is f
2
First non-repeating character is f
6

First non-repeating character is f
7
First non-repeating character is f
3
First non-repeating character is f
9__
First non-repeating character is f
1

First non-repeating character is f
7
First non-repeating character is f
3

First non-repeating character is f
0
First non-repeating character is f
5
First non-repeating character is f
6

First non-repeating character is f
7index
First non-repeating character is f
9=
First non-repeating character is f
2

First non-repeating character is f
1 index =
First non-repeating character is f
2
First non-repeating character is f
6

First non-repeating character is f
0
First non-repeating character is f
9
First non-repeating character is f
0
First non-repeating character is f
1
First non-repeating character is f
2

First non-repeating character is f
5
First non-repeating character is f
6

First non-repeating character is f
0
First non-repeating character is f
9
First non-repeating character is f
0
First non-repeating character is f
8
First non-repeating character is f
9

Đầ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 f
0
First non-repeating character is f
6
First non-repeating character is f
0=0 =1

First non-repeating character is f
7
First non-repeating character is f
1 =4

=5=6

=5=8=9

"geeksforgeeks"0"geeksforgeeks"1

=5"geeksforgeeks"3"geeksforgeeks"4

First non-repeating character is f
7"geeksforgeeks"6

First non-repeating character is f
0"geeksforgeeks"6

First non-repeating character is f
0=8index 1

=5index 3"geeksforgeeks"4

First non-repeating character is f
0"geeksforgeeks"3"geeksforgeeks"4

"geeksforgeeks"6

=0

First non-repeating character is f
00

string 6

First non-repeating character is f
0
First non-repeating character is f
03"geeksforgeeks""geeksforgeeks"4

First non-repeating character is f
0
First non-repeating character is f
07

"geeksforgeeks"6

Java

First non-repeating character is f
09
First non-repeating character is f
10

First non-repeating character is f
11
First non-repeating character is f
12

First non-repeating character is f
13
First non-repeating character is f
14
First non-repeating character is f
15 string 4
First non-repeating character is f
17

First non-repeating character is f
13string 6

First non-repeating character is f
0
First non-repeating character is f
6
First non-repeating character is f
0=0
First non-repeating character is f
24
First non-repeating character is f
25
First non-repeating character is f
26

First non-repeating character is f
27
First non-repeating character is f
1
First non-repeating character is f
29
First non-repeating character is f
2
First non-repeating character is f
31
First non-repeating character is f
2

First non-repeating character is f
7
First non-repeating character is f
35=9
First non-repeating character is f
37

First non-repeating character is f
7
First non-repeating character is f
3"geeksforgeeks"4

First non-repeating character is f
27"geeksforgeeks"6

First non-repeating character is f
0"geeksforgeeks"6

First non-repeating character is f
0"geeksforgeeks"3"geeksforgeeks"4

First non-repeating character is f
13"geeksforgeeks"6

First non-repeating character is f
13
First non-repeating character is f
14
First non-repeating character is f
15 string 4
First non-repeating character is f
54

First non-repeating character is f
0
First non-repeating character is f
56"geeksforgeeks""geeksforgeeks"4

First non-repeating character is f
0
First non-repeating character is f
07

First non-repeating character is f
13"geeksforgeeks"6

"geeksforgeeks"6

Python3

First non-repeating character is f
64
First non-repeating character is f
65

First non-repeating character is f
0
First non-repeating character is f
6
First non-repeating character is f
7
First non-repeating character is f
8
First non-repeating character is f
70

First non-repeating character is f
7
First non-repeating character is f
1
First non-repeating character is f
73
First non-repeating character is f
9__12

=5

First non-repeating character is f
9
First non-repeating character is f
0
First non-repeating character is f
8
First non-repeating character is f
86

=5

First non-repeating character is f
3

First non-repeating character is f
0"geeksforgeeks"3

First non-repeating character is f
91=
First non-repeating character is f
93

First non-repeating character is f
94

C#

string 1

First non-repeating character is f
96

First non-repeating character is f
14
First non-repeating character is f
15
First non-repeating character is f
11
First non-repeating character is f
12

First non-repeating character is f
0
First non-repeating character is f
14
First non-repeating character is f
15 string 4
First non-repeating character is f
05
First non-repeating character is f
06
First non-repeating character is f
07

First non-repeating character is f
0string 6

First non-repeating character is f
7
First non-repeating character is f
6
First non-repeating character is f
0=0
First non-repeating character is f
14

=5

First non-repeating character is f
1
First non-repeating character is f
17

First non-repeating character is f
18
First non-repeating character is f
19

First non-repeating character is f
18
First non-repeating character is f
21

First non-repeating character is f
22=9

First non-repeating character is f
22
First non-repeating character is f
25

First non-repeating character is f
18
First non-repeating character is f
3"geeksforgeeks"4

=5"geeksforgeeks"6

First non-repeating character is f
7"geeksforgeeks"6

First non-repeating character is f
7"geeksforgeeks"3"geeksforgeeks"4

First non-repeating character is f
0"geeksforgeeks"6

First non-repeating character is f
0
First non-repeating character is f
39
First non-repeating character is f
15 string 4
First non-repeating character is f
42

First non-repeating character is f
0string 6

First non-repeating character is f
7
First non-repeating character is f
06
First non-repeating character is f
47"geeksforgeeks""geeksforgeeks"4

First non-repeating character is f
7
First non-repeating character is f
07

First non-repeating character is f
0"geeksforgeeks"6

"geeksforgeeks"6

JavaScript

First non-repeating character is f
55

First non-repeating character is f
56
First non-repeating character is f
57

First non-repeating character is f
58
First non-repeating character is f
6
First non-repeating character is f
60

First non-repeating character is f
58string 6

First non-repeating character is f
63
First non-repeating character is f
1
First non-repeating character is f
65

First non-repeating character is f
63string 6

First non-repeating character is f
68
First non-repeating character is f
69

First non-repeating character is f
68
First non-repeating character is f
3

First non-repeating character is f
63"geeksforgeeks"6

First non-repeating character is f
58"geeksforgeeks"6

First non-repeating character is f
58"geeksforgeeks"3

"geeksforgeeks"6

First non-repeating character is f
79
First non-repeating character is f
93

First non-repeating character is f
94

First non-repeating character is f
82

Đầ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 f
83

string 1 string 2 string 3

First non-repeating character is f
87

=0

First non-repeating character is f
89
First non-repeating character is f
90
First non-repeating character is f
91

string 6

First non-repeating character is f
0=0
First non-repeating character is f
95=0
First non-repeating character is f
97
First non-repeating character is f
98
First non-repeating character is f
0
First non-repeating character is f
00
First non-repeating character is f
0=0
First non-repeating character is f
03

First non-repeating character is f
0=0
First non-repeating character is f
06

First non-repeating character is f
0
First non-repeating character is f
6
First non-repeating character is f
09

First non-repeating character is f
7
First non-repeating character is f
11

First non-repeating character is f
0"geeksforgeeks"3
First non-repeating character is f
14

"geeksforgeeks"6

=0

First non-repeating character is f
17
First non-repeating character is f
90
First non-repeating character is f
91

string 6

First non-repeating character is f
0=0
First non-repeating character is f
23

First non-repeating character is f
0=0
First non-repeating character is f
26

First non-repeating character is f
0
First non-repeating character is f
6
First non-repeating character is f
29

First non-repeating character is f
7
First non-repeating character is f
1
First non-repeating character is f
32

=5

First non-repeating character is f
34

=5

First non-repeating character is f
3"geeksforgeeks"4

First non-repeating character is f
7"geeksforgeeks"6

First non-repeating character is f
0"geeksforgeeks"6

First non-repeating character is f
0
First non-repeating character is f
43
First non-repeating character is f
44

First non-repeating character is f
0"geeksforgeeks"3
First non-repeating character is f
47

"geeksforgeeks"6

=0

First non-repeating character is f
00

string 6

First non-repeating character is f
0
First non-repeating character is f
90
First non-repeating character is f
54"geeksforgeeks""geeksforgeeks"4

First non-repeating character is f
0=0
First non-repeating character is f
59

First non-repeating character is f
0
First non-repeating character is f
1
First non-repeating character is f
62

First non-repeating character is f
7=8index 1

First non-repeating character is f
18index 3"geeksforgeeks"4

First non-repeating character is f
0
First non-repeating character is f
5

First non-repeating character is f
7=8=9

First non-repeating character is f
74
First non-repeating character is f
75

First non-repeating character is f
0
First non-repeating character is f
77
First non-repeating character is f
78

First non-repeating character is f
0"geeksforgeeks"3
First non-repeating character is f
81

"geeksforgeeks"6

C

First non-repeating character is f
83

First non-repeating character is f
84

First non-repeating character is f
87

=0

First non-repeating character is f
89
First non-repeating character is f
90
First non-repeating character is f
91

string 6

First non-repeating character is f
0=0
First non-repeating character is f
95=0
First non-repeating character is f
97
First non-repeating character is f
98
First non-repeating character is f
0
First non-repeating character is f
00
First non-repeating character is f
0=0
First non-repeating character is f
03

First non-repeating character is f
0=0
First non-repeating character is f
06

First non-repeating character is f
0
First non-repeating character is f
6
First non-repeating character is f
09

First non-repeating character is f
7
First non-repeating character is f
11

First non-repeating character is f
0"geeksforgeeks"3
First non-repeating character is f
14

"geeksforgeeks"6

=0

First non-repeating character is f
17
First non-repeating character is f
90
First non-repeating character is f
91

string 6

First non-repeating character is f
0=0
First non-repeating character is f
23

First non-repeating character is f
0=0
First non-repeating character is f
26

First non-repeating character is f
0
First non-repeating character is f
6
First non-repeating character is f
29

First non-repeating character is f
7
First non-repeating character is f
1
First non-repeating character is f
32

=5

First non-repeating character is f
34

=5

First non-repeating character is f
3"geeksforgeeks"4

First non-repeating character is f
7"geeksforgeeks"6

First non-repeating character is f
0"geeksforgeeks"6

First non-repeating character is f
0
First non-repeating character is f
43
First non-repeating character is f
44

First non-repeating character is f
0"geeksforgeeks"3
First non-repeating character is f
47

"geeksforgeeks"6

=0

First non-repeating character is f
00

string 6

First non-repeating character is f
0
First non-repeating character is f
90
First non-repeating character is f
54"geeksforgeeks""geeksforgeeks"4

First non-repeating character is f
0=0
First non-repeating character is f
59

First non-repeating character is f
0
First non-repeating character is f
1
First non-repeating character is f
62

First non-repeating character is f
7
First non-repeating character is f
62
First non-repeating character is f
0index 1

First non-repeating character is f
65index 3
First non-repeating character is f
67

First non-repeating character is f
0
First non-repeating character is f
5

First non-repeating character is f
7
First non-repeating character is f
62
First non-repeating character is f
0
First non-repeating character is f
73
First non-repeating character is f
74

First non-repeating character is f
65
First non-repeating character is f
76

First non-repeating character is f
0"geeksforgeeks"3
First non-repeating character is f
81

First non-repeating character is f
0"geeksforgeeks"3
First non-repeating character is f
81

"geeksforgeeks"6

C

First non-repeating character is f
83

First non-repeating character is f
0
First non-repeating character is f
777
First non-repeating character is f
78

Java

First non-repeating character is f
09
First non-repeating character is f
85

First non-repeating character is f
11
First non-repeating character is f
12

First non-repeating character is f
0string 6

First non-repeating character is f
0
First non-repeating character is f
15
First non-repeating character is f
90 =0
First non-repeating character is f
92
First non-repeating character is f
93"geeksforgeeks"4

=5

First non-repeating character is f
16

First non-repeating character is f
0"geeksforgeeks"6

First non-repeating character is f
0
First non-repeating character is f
15
First non-repeating character is f
90
First non-repeating character is f
98
First non-repeating character is f
99
First non-repeating character is f
90
First non-repeating character is f
01

First non-repeating character is f
0
First non-repeating character is f
15 string 4
First non-repeating character is f
05

First non-repeating character is f
7
First non-repeating character is f
26

First non-repeating character is f
7
First non-repeating character is f
6
First non-repeating character is f
0=0
First non-repeating character is f
24
First non-repeating character is f
25
First non-repeating character is f
14

First non-repeating character is f
0
First non-repeating character is f
15 =0
First non-repeating character is f
22

First non-repeating character is f
0string 6

First non-repeating character is f
18
First non-repeating character is f
34

First non-repeating character is f
18
First non-repeating character is f
3"geeksforgeeks"4

=5"geeksforgeeks"6

First non-repeating character is f
7"geeksforgeeks"6

First non-repeating character is f
7=0
First non-repeating character is f
29
First non-repeating character is f
2
First non-repeating character is f
31

First non-repeating character is f
0"geeksforgeeks"6

First non-repeating character is f
7
First non-repeating character is f
6
First non-repeating character is f
34
First non-repeating character is f
25
First non-repeating character is f
36

First non-repeating character is f
0string 6

First non-repeating character is f
7
First non-repeating character is f
64"geeksforgeeks""geeksforgeeks"4

=5

First non-repeating character is f
1
First non-repeating character is f
39
First non-repeating character is f
2
First non-repeating character is f
33

First non-repeating character is f
7
First non-repeating character is f
35

First non-repeating character is f
7"geeksforgeeks"3
First non-repeating character is f
47

First non-repeating character is f
18
First non-repeating character is f
76
First non-repeating character is f
77

First non-repeating character is f
78
First non-repeating character is f
79
First non-repeating character is f
80

First non-repeating character is f
18
First non-repeating character is f
82=9

First non-repeating character is f
78
First non-repeating character is f
85

First non-repeating character is f
0"geeksforgeeks"6

"geeksforgeeks"6

Python3

First non-repeating character is f
0
First non-repeating character is f
14
First non-repeating character is f
15 string 4
First non-repeating character is f
60

First non-repeating character is f
7=0
First non-repeating character is f
59

=5

First non-repeating character is f
73
First non-repeating character is f
2

First non-repeating character is f
89=
First non-repeating character is f
93

First non-repeating character is f
64
First non-repeating character is f
93

Các

First non-repeating character is f
0
First non-repeating character is f
6
First non-repeating character is f
7
First non-repeating character is f
8
First non-repeating character is f
9

First non-repeating character is f
7string 08string 09string 10
First non-repeating character is f
9=

First non-repeating character is f
0"geeksforgeeks"3 string 16

First non-repeating character is f
64 string 18

First non-repeating character is f
89=
First non-repeating character is f
93

First non-repeating character is f
64
First non-repeating character is f
93

Các

=5

First non-repeating character is f
3

First non-repeating character is f
0
First non-repeating character is f
6
First non-repeating character is f
7
First non-repeating character is f
8
First non-repeating character is f
9

First non-repeating character is f
7string 08string 09string 10
First non-repeating character is f
9=

First non-repeating character is f
0"geeksforgeeks"3 string 16

First non-repeating character is f
64 string 18

First non-repeating character is f
1 index =
First non-repeating character is f
2
First non-repeating character is f
6

First non-repeating character is f
0
First non-repeating character is f
9
First non-repeating character is f
0
First non-repeating character is f
1
First non-repeating character is f
2

First non-repeating character is f
5
First non-repeating character is f
6

First non-repeating character is f
0
First non-repeating character is f
9
First non-repeating character is f
0
First non-repeating character is f
8string 83

C#

string 1

First non-repeating character is f
96

string 1 string 87

First non-repeating character is f
11
First non-repeating character is f
12

First non-repeating character is f
0
First non-repeating character is f
15 =0 string 93

First non-repeating character is f
0
First non-repeating character is f
15
First non-repeating character is f
90string 97
First non-repeating character is f
99
First non-repeating character is f
90
First non-repeating character is f
01

First non-repeating character is f
0
First non-repeating character is f
15 string 4 =04
First non-repeating character is f
06 =06

First non-repeating character is f
0string 6

First non-repeating character is f
7
First non-repeating character is f
6
First non-repeating character is f
0=0 =13

=5=15

First non-repeating character is f
0"geeksforgeeks"6

First non-repeating character is f
0
First non-repeating character is f
15 =0
First non-repeating character is f
17
First non-repeating character is f
06 =06

First non-repeating character is f
0string 6

First non-repeating character is f
7
First non-repeating character is f
26

First non-repeating character is f
7=0
First non-repeating character is f
26

First non-repeating character is f
7
First non-repeating character is f
6 =33

=5

First non-repeating character is f
1 =36

First non-repeating character is f
18
First non-repeating character is f
34

First non-repeating character is f
18
First non-repeating character is f
3"geeksforgeeks"4

=5"geeksforgeeks"6

First non-repeating character is f
7"geeksforgeeks"6

First non-repeating character is f
7"geeksforgeeks"3
First non-repeating character is f
47

First non-repeating character is f
0"geeksforgeeks"6

First non-repeating character is f
0
First non-repeating character is f
14
First non-repeating character is f
15 string 4
First non-repeating character is f
42

First non-repeating character is f
0string 6

First non-repeating character is f
7
First non-repeating character is f
06 =60"geeksforgeeks""geeksforgeeks"4

First non-repeating character is f
7=0
First non-repeating character is f
59

First non-repeating character is f
7=67

=5=69

First non-repeating character is f
18
First non-repeating character is f
76=72

First non-repeating character is f
78
First non-repeating character is f
79=75

First non-repeating character is f
78
First non-repeating character is f
79
First non-repeating character is f
80

First non-repeating character is f
18
First non-repeating character is f
82=81

First non-repeating character is f
78
First non-repeating character is f
79=84 =85

First non-repeating character is f
0"geeksforgeeks"6

"geeksforgeeks"6

PHP

=89

=90 =91

First non-repeating character is f
56 =04=98
First non-repeating character is f
2

string 6

First non-repeating character is f
0"geeksforgeeks"02 =92"geeksforgeeks"4

First non-repeating character is f
0
First non-repeating character is f
6
First non-repeating character is f
0"geeksforgeeks"08 "geeksforgeeks"09

"geeksforgeeks"10"geeksforgeeks"08 "geeksforgeeks"12"geeksforgeeks"13

First non-repeating character is f
0=98"geeksforgeeks"16"geeksforgeeks"08"geeksforgeeks"18

First non-repeating character is f
7=92"geeksforgeeks"21=98
First non-repeating character is f
97"geeksforgeeks"08"geeksforgeeks"25

"geeksforgeeks"6

First non-repeating character is f
56
First non-repeating character is f
17=98
First non-repeating character is f
2

string 6

First non-repeating character is f
0"geeksforgeeks"02 =92"geeksforgeeks"4

First non-repeating character is f
0=04=98
First non-repeating character is f
67

First non-repeating character is f
0
First non-repeating character is f
6
First non-repeating character is f
0"geeksforgeeks"08 "geeksforgeeks"09

First non-repeating character is f
0
First non-repeating character is f
6
First non-repeating character is f
0"geeksforgeeks"08 "geeksforgeeks"09

"geeksforgeeks"10"geeksforgeeks"08 "geeksforgeeks"12"geeksforgeeks"13

First non-repeating character is f
0=98"geeksforgeeks"16"geeksforgeeks"08"geeksforgeeks"18

First non-repeating character is f
0string 6

First non-repeating character is f
56
First non-repeating character is f
17=98
First non-repeating character is f
2

First non-repeating character is f
7string 6

First non-repeating character is f
0"geeksforgeeks"41 "geeksforgeeks"42

=5

First non-repeating character is f
3"geeksforgeeks"4

First non-repeating character is f
7"geeksforgeeks"6

First non-repeating character is f
0"geeksforgeeks"6

First non-repeating character is f
7
First non-repeating character is f
1
First non-repeating character is f
0=92"geeksforgeeks"21=98
First non-repeating character is f
97"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 f
67

index 01index 02"geeksforgeeks"4

First non-repeating character is f
5

First non-repeating character is f
1
First non-repeating character is f
0"geeksforgeeks"41 "geeksforgeeks"97

=5index 09index 00

First non-repeating character is f
65=98
First non-repeating character is f
97"geeksforgeeks"41index 15

index 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 f
87

Dưới đây là việc thực hiện phương pháp trên.

string 6

First non-repeating character is f
0index 28=0index 30=0index 32

string 1 string 2 string 3

First non-repeating character is f
7index 39

First non-repeating character is f
7index 41

First non-repeating character is f
0"geeksforgeeks"6

=0

First non-repeating character is f
17
First non-repeating character is f
90
First non-repeating character is f
91

First non-repeating character is f
0
First non-repeating character is f
6
First non-repeating character is f
0=0 index 37

First non-repeating character is f
0=0 index 46

=5index 56

First non-repeating character is f
0
First non-repeating character is f
6
First non-repeating character is f
0=0 index 51

"geeksforgeeks"6

First non-repeating character is f
7
First non-repeating character is f
1 index 54

string 6

First non-repeating character is f
0"geeksforgeeks"3 index 59

=0

First non-repeating character is f
00

First non-repeating character is f
0
First non-repeating character is f
90
First non-repeating character is f
54"geeksforgeeks""geeksforgeeks"4

First non-repeating character is f
7
First non-repeating character is f
62
First non-repeating character is f
0index 78

First non-repeating character is f
65index 80
First non-repeating character is f
67

First non-repeating character is f
0
First non-repeating character is f
5

First non-repeating character is f
7
First non-repeating character is f
62
First non-repeating character is f
0=81

First non-repeating character is f
65index 89
First non-repeating character is f
74

First non-repeating character is f
65
First non-repeating character is f
76

First non-repeating character is f
0"geeksforgeeks"3
First non-repeating character is f
81

"geeksforgeeks"6

C

index 97

First non-repeating character is f
83

First non-repeating character is f
84

First non-repeating character is f
87

First non-repeating character is f
001
First non-repeating character is f
002

First non-repeating character is f
0=0
First non-repeating character is f
14

First non-repeating character is f
0=0
First non-repeating character is f
47

First non-repeating character is f
009

First non-repeating character is f
001
First non-repeating character is f
011
First non-repeating character is f
90
First non-repeating character is f
91

string 6

First non-repeating character is f
0
First non-repeating character is f
001
First non-repeating character is f
017
First non-repeating character is f
001
First non-repeating character is f
019
First non-repeating character is f
98
First non-repeating character is f
0

First non-repeating character is f
7
First non-repeating character is f
00
First non-repeating character is f
0
First non-repeating character is f
001
First non-repeating character is f
026

First non-repeating character is f
0=0
First non-repeating character is f
06

First non-repeating character is f
0
First non-repeating character is f
6
First non-repeating character is f
29

First non-repeating character is f
7
First non-repeating character is f
034

First non-repeating character is f
7
First non-repeating character is f
1
First non-repeating character is f
037

=5

First non-repeating character is f
039

First non-repeating character is f
0"geeksforgeeks"6

First non-repeating character is f
0"geeksforgeeks"3
First non-repeating character is f
14

"geeksforgeeks"6

=0

First non-repeating character is f
17
First non-repeating character is f
90
First non-repeating character is f
91

string 6

First non-repeating character is f
0
First non-repeating character is f
001
First non-repeating character is f
053

First non-repeating character is f
0=0
First non-repeating character is f
056

First non-repeating character is f
0
First non-repeating character is f
6
First non-repeating character is f
059

First non-repeating character is f
7
First non-repeating character is f
1
First non-repeating character is f
062

=5

First non-repeating character is f
064

First non-repeating character is f
0"geeksforgeeks"6

First non-repeating character is f
0
First non-repeating character is f
43
First non-repeating character is f
44

First non-repeating character is f
0"geeksforgeeks"3
First non-repeating character is f
072

"geeksforgeeks"6

=0

First non-repeating character is f
00

string 6

First non-repeating character is f
0
First non-repeating character is f
90
First non-repeating character is f
54"geeksforgeeks""geeksforgeeks"4

First non-repeating character is f
0=0
First non-repeating character is f
59

First non-repeating character is f
0
First non-repeating character is f
1 index 74

First non-repeating character is f
7
First non-repeating character is f
62
First non-repeating character is f
0"geeksforgeeks"99

First non-repeating character is f
65index 02
First non-repeating character is f
67

First non-repeating character is f
0
First non-repeating character is f
5

First non-repeating character is f
7
First non-repeating character is f
62
First non-repeating character is f
0=81

First non-repeating character is f
65index 89
First non-repeating character is f
74

First non-repeating character is f
65
First non-repeating character is f
76

First non-repeating character is f
0
First non-repeating character is f
77
First non-repeating character is f
78

First non-repeating character is f
0"geeksforgeeks"3
First non-repeating character is f
81

"geeksforgeeks"6

Java

First non-repeating character is f
09
First non-repeating character is f
10

First non-repeating character is f
11
First non-repeating character is f
116

First non-repeating character is f
0=0
First non-repeating character is f
119

First non-repeating character is f
0
First non-repeating character is f
14
First non-repeating character is f
12222222
First non-repeating character is f
124

First non-repeating character is f
0string 6

First non-repeating character is f
7
First non-repeating character is f
128
First non-repeating character is f
129
First non-repeating character is f
2"geeksforgeeks"4

First non-repeating character is f
7
First non-repeating character is f
128
First non-repeating character is f
134

First non-repeating character is f
0"geeksforgeeks"6

First non-repeating character is f
0
First non-repeating character is f
14 string 4
First non-repeating character is f
140
First non-repeating character is f
128
First non-repeating character is f
142

"geeksforgeeks"6

First non-repeating character is f
11
First non-repeating character is f
12

First non-repeating character is f
0
First non-repeating character is f
15
First non-repeating character is f
90 =0
First non-repeating character is f
92
First non-repeating character is f
93"geeksforgeeks"4

First non-repeating character is f
0
First non-repeating character is f
15
First non-repeating character is f
155

First non-repeating character is f
7"geeksforgeeks"72
First non-repeating character is f
99
First non-repeating character is f
159

First non-repeating character is f
0
First non-repeating character is f
15 string 4
First non-repeating character is f
05

First non-repeating character is f
0string 6

First non-repeating character is f
7
First non-repeating character is f
6
First non-repeating character is f
0=0
First non-repeating character is f
24
First non-repeating character is f
25
First non-repeating character is f
36

=5

First non-repeating character is f
1
First non-repeating character is f
175

First non-repeating character is f
18
First non-repeating character is f
177

=5"geeksforgeeks"6

=5

First non-repeating character is f
5 string 6

First non-repeating character is f
18
First non-repeating character is f
184
First non-repeating character is f
99
First non-repeating character is f
186

=5"geeksforgeeks"6

First non-repeating character is f
7"geeksforgeeks"6

First non-repeating character is f
0"geeksforgeeks"6

First non-repeating character is f
0
First non-repeating character is f
15 =0
First non-repeating character is f
22

First non-repeating character is f
0string 6

First non-repeating character is f
7
First non-repeating character is f
26

First non-repeating character is f
7=0
First non-repeating character is f
203

First non-repeating character is f
7
First non-repeating character is f
6
First non-repeating character is f
206

First non-repeating character is f
74
First non-repeating character is f
208

=5=0

First non-repeating character is f
211

=5=0

First non-repeating character is f
214

=5

First non-repeating character is f
1
First non-repeating character is f
217
First non-repeating character is f
2
First non-repeating character is f
219

First non-repeating character is f
18
First non-repeating character is f
221

=5"geeksforgeeks"6

First non-repeating character is f
7"geeksforgeeks"6

First non-repeating character is f
7"geeksforgeeks"3
First non-repeating character is f
072

First non-repeating character is f
0"geeksforgeeks"6

First non-repeating character is f
0
First non-repeating character is f
14
First non-repeating character is f
15 string 4
First non-repeating character is f
60

First non-repeating character is f
0string 6

First non-repeating character is f
7
First non-repeating character is f
64"geeksforgeeks""geeksforgeeks"4

First non-repeating character is f
7=0
First non-repeating character is f
59

First non-repeating character is f
7
First non-repeating character is f
35

=5

First non-repeating character is f
248

First non-repeating character is f
18
First non-repeating character is f
76
First non-repeating character is f
251

First non-repeating character is f
78
First non-repeating character is f
79
First non-repeating character is f
254

First non-repeating character is f
18
First non-repeating character is f
82=9

First non-repeating character is f
78
First non-repeating character is f
85

First non-repeating character is f
0"geeksforgeeks"6

"geeksforgeeks"6

Python3

First non-repeating character is f
09
First non-repeating character is f
264

First non-repeating character is f
89=
First non-repeating character is f
93

First non-repeating character is f
64
First non-repeating character is f
17
First non-repeating character is f
270
First non-repeating character is f
271

First non-repeating character is f
0
First non-repeating character is f
273=
First non-repeating character is f
275
First non-repeating character is f
6
First non-repeating character is f
7__

First non-repeating character is f
0
First non-repeating character is f
6
First non-repeating character is f
7
First non-repeating character is f
8
First non-repeating character is f
279
First non-repeating character is f
286

First non-repeating character is f
7
First non-repeating character is f
288=
First non-repeating character is f
97
First non-repeating character is f
25index 30__125
First non-repeating character is f
294

First non-repeating character is f
0
First non-repeating character is f
6
First non-repeating character is f
7__18

Các

Các

First non-repeating character is f
0
First non-repeating character is f
327=
First non-repeating character is f
329

First non-repeating character is f
0
First non-repeating character is f
6
First non-repeating character is f
7
First non-repeating character is f
8
First non-repeating character is f
279
First non-repeating character is f
286

First non-repeating character is f
7
First non-repeating character is f
288=
First non-repeating character is f
97
First non-repeating character is f
25index 30__125
First non-repeating character is f
294

First non-repeating character is f
0
First non-repeating character is f
6
First non-repeating character is f
7__18

Các

Các

First non-repeating character is f
0
First non-repeating character is f
327=
First non-repeating character is f
329

First non-repeating character is f
7
First non-repeating character is f
1
First non-repeating character is f
338
First non-repeating character is f
25
First non-repeating character is f
93

First non-repeating character is f
0
First non-repeating character is f
9
First non-repeating character is f
0
First non-repeating character is f
1
First non-repeating character is f
2

First non-repeating character is f
5
First non-repeating character is f
6

First non-repeating character is f
0
First non-repeating character is f
9
First non-repeating character is f
0=9index 30
First non-repeating character is f
270
First non-repeating character is f
381

C#

First non-repeating character is f
0"geeksforgeeks"3
First non-repeating character is f
354

First non-repeating character is f
11
First non-repeating character is f
116

First non-repeating character is f
0=0
First non-repeating character is f
119

First non-repeating character is f
0
First non-repeating character is f
14
First non-repeating character is f
12222
First non-repeating character is f
124

First non-repeating character is f
0string 6

First non-repeating character is f
7
First non-repeating character is f
128
First non-repeating character is f
401

First non-repeating character is f
7
First non-repeating character is f
128
First non-repeating character is f
134

First non-repeating character is f
0"geeksforgeeks"6

First non-repeating character is f
0
First non-repeating character is f
14
First non-repeating character is f
409 string 4
First non-repeating character is f
140
First non-repeating character is f
128
First non-repeating character is f
142

"geeksforgeeks"6

First non-repeating character is f
11
First non-repeating character is f
12

First non-repeating character is f
0
First non-repeating character is f
14
First non-repeating character is f
419 =0 string 93

First non-repeating character is f
0
First non-repeating character is f
14
First non-repeating character is f
15
First non-repeating character is f
425
First non-repeating character is f
90
First non-repeating character is f
427

First non-repeating character is f
7"geeksforgeeks"72
First non-repeating character is f
99
First non-repeating character is f
425
First non-repeating character is f
90
First non-repeating character is f
433

First non-repeating character is f
0
First non-repeating character is f
14
First non-repeating character is f
15 string 4 =04
First non-repeating character is f
06 =06

First non-repeating character is f
0string 6

First non-repeating character is f
7
First non-repeating character is f
6
First non-repeating character is f
0=0
First non-repeating character is f
447

=5

First non-repeating character is f
1
First non-repeating character is f
450

First non-repeating character is f
18
First non-repeating character is f
452

=5"geeksforgeeks"6

=5

First non-repeating character is f
5 string 6

First non-repeating character is f
18
First non-repeating character is f
459
First non-repeating character is f
99
First non-repeating character is f
461

=5"geeksforgeeks"6

First non-repeating character is f
7"geeksforgeeks"6

First non-repeating character is f
0"geeksforgeeks"6

First non-repeating character is f
0
First non-repeating character is f
39
First non-repeating character is f
15 =0
First non-repeating character is f
17
First non-repeating character is f
06 =06

First non-repeating character is f
0string 6

First non-repeating character is f
7
First non-repeating character is f
26

First non-repeating character is f
7=0
First non-repeating character is f
481=0
First non-repeating character is f
483

First non-repeating character is f
7
First non-repeating character is f
6 =33

=5

First non-repeating character is f
1
First non-repeating character is f
489

First non-repeating character is f
18
First non-repeating character is f
491

First non-repeating character is f
18
First non-repeating character is f
493

=5"geeksforgeeks"6

First non-repeating character is f
7"geeksforgeeks"6

First non-repeating character is f
7"geeksforgeeks"3
First non-repeating character is f
072

First non-repeating character is f
0"geeksforgeeks"6

First non-repeating character is f
0
First non-repeating character is f
14
First non-repeating character is f
15 string 4
First non-repeating character is f
507
First non-repeating character is f
06
First non-repeating character is f
509

First non-repeating character is f
0string 6

First non-repeating character is f
7
First non-repeating character is f
06 =60"geeksforgeeks""geeksforgeeks"4

First non-repeating character is f
7=0
First non-repeating character is f
59

First non-repeating character is f
7=67

=5

First non-repeating character is f
523=0
First non-repeating character is f
525

First non-repeating character is f
18
First non-repeating character is f
76
First non-repeating character is f
251

First non-repeating character is f
78
First non-repeating character is f
79
First non-repeating character is f
254

First non-repeating character is f
18
First non-repeating character is f
82=9

First non-repeating character is f
78=85

First non-repeating character is f
0"geeksforgeeks"6

"geeksforgeeks"6

JavaScript

First non-repeating character is f
55

First non-repeating character is f
541

First non-repeating character is f
56
First non-repeating character is f
543

string 6

First non-repeating character is f
0
First non-repeating character is f
546
First non-repeating character is f
99
First non-repeating character is f
548

First non-repeating character is f
0
First non-repeating character is f
6
First non-repeating character is f
551

First non-repeating character is f
7
First non-repeating character is f
553

First non-repeating character is f
0"geeksforgeeks"6

First non-repeating character is f
0
First non-repeating character is f
6
First non-repeating character is f
558

First non-repeating character is f
7
First non-repeating character is f
560

First non-repeating character is f
7
First non-repeating character is f
562

First non-repeating character is f
0"geeksforgeeks"6

First non-repeating character is f
0
First non-repeating character is f
566

First non-repeating character is f
0
First non-repeating character is f
6
First non-repeating character is f
569

First non-repeating character is f
7
First non-repeating character is f
1
First non-repeating character is f
572

=5

First non-repeating character is f
574

First non-repeating character is f
0"geeksforgeeks"3 index 59

"geeksforgeeks"6

First non-repeating character is f
579"geeksforgeeks""geeksforgeeks"4

First non-repeating character is f
582

First non-repeating character is f
1
First non-repeating character is f
584

First non-repeating character is f
0
First non-repeating character is f
586
First non-repeating character is f
1
First non-repeating character is f
67

First non-repeating character is f
5

First non-repeating character is f
0
First non-repeating character is f
586=9
First non-repeating character is f
593

First non-repeating character is f
82

Đầ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 f
595

First non-repeating character is f
83

string 1 string 2 string 3

=0

First non-repeating character is f
601

string 6

First non-repeating character is f
0=0
First non-repeating character is f
605

First non-repeating character is f
0
First non-repeating character is f
6
First non-repeating character is f
0=0
First non-repeating character is f
610

First non-repeating character is f
7
First non-repeating character is f
612

First non-repeating character is f
0
First non-repeating character is f
6
First non-repeating character is f
0=0
First non-repeating character is f
617

First non-repeating character is f
7
First non-repeating character is f
1
First non-repeating character is f
620

=5

First non-repeating character is f
622

First non-repeating character is f
7"geeksforgeeks"6

First non-repeating character is f
7
First non-repeating character is f
5 string 6

=5

First non-repeating character is f
629

First non-repeating character is f
7"geeksforgeeks"6

First non-repeating character is f
0"geeksforgeeks"6

First non-repeating character is f
0=0 index 46

First non-repeating character is f
0
First non-repeating character is f
6
First non-repeating character is f
0=0
First non-repeating character is f
641

First non-repeating character is f
7
First non-repeating character is f
1
First non-repeating character is f
644

=5

First non-repeating character is f
646

First non-repeating character is f
0"geeksforgeeks"6

First non-repeating character is f
0____21
First non-repeating character is f
651

First non-repeating character is f
7"geeksforgeeks"3
First non-repeating character is f
654

First non-repeating character is f
0
First non-repeating character is f
5

First non-repeating character is f
7"geeksforgeeks"3 index 59

"geeksforgeeks"6

=0

First non-repeating character is f
00

string 6

First non-repeating character is f
0
First non-repeating character is f
665

First non-repeating character is f
0=60"geeksforgeeks""geeksforgeeks"4

First non-repeating character is f
0=0
First non-repeating character is f
672

First non-repeating character is f
0____21
First non-repeating character is f
675

First non-repeating character is f
7=8index 1

First non-repeating character is f
18index 3"geeksforgeeks"4

First non-repeating character is f
0
First non-repeating character is f
5

First non-repeating character is f
7=8=9

First non-repeating character is f
74
First non-repeating character is f
688

First non-repeating character is f
0"geeksforgeeks"3
First non-repeating character is f
81

"geeksforgeeks"6

Java

First non-repeating character is f
14
First non-repeating character is f
11
First non-repeating character is f
12

First non-repeating character is f
0
First non-repeating character is f
14
First non-repeating character is f
15 =0
First non-repeating character is f
22

First non-repeating character is f
0string 6

First non-repeating character is f
7=0
First non-repeating character is f
705

=5"geeksforgeeks"72

First non-repeating character is f
99 =0
First non-repeating character is f
97
First non-repeating character is f
93
First non-repeating character is f
712

First non-repeating character is f
7
First non-repeating character is f
6
First non-repeating character is f
0=0
First non-repeating character is f
24
First non-repeating character is f
25
First non-repeating character is f
719
First non-repeating character is f
93
First non-repeating character is f
721

=5

First non-repeating character is f
723
First non-repeating character is f
2"geeksforgeeks"4

First non-repeating character is f
7
First non-repeating character is f
6
First non-repeating character is f
0=0
First non-repeating character is f
24
First non-repeating character is f
25
First non-repeating character is f
36

=5

First non-repeating character is f
1
First non-repeating character is f
735
First non-repeating character is f
2
First non-repeating character is f
33

First non-repeating character is f
18
First non-repeating character is f
739

=5"geeksforgeeks"6

=5

First non-repeating character is f
5 string 6

First non-repeating character is f
18
First non-repeating character is f
746
First non-repeating character is f
747"geeksforgeeks"4

=5"geeksforgeeks"6

First non-repeating character is f
7"geeksforgeeks"6

First non-repeating character is f
7=0
First non-repeating character is f
755

First non-repeating character is f
7
First non-repeating character is f
6
First non-repeating character is f
0=0
First non-repeating character is f
24
First non-repeating character is f
25
First non-repeating character is f
719
First non-repeating character is f
93
First non-repeating character is f
764

=5

First non-repeating character is f
1
First non-repeating character is f
767
First non-repeating character is f
25
First non-repeating character is f
2

First non-repeating character is f
18
First non-repeating character is f
771

First non-repeating character is f
7"geeksforgeeks"6

First non-repeating character is f
7
First non-repeating character is f
1
First non-repeating character is f
776

=5"geeksforgeeks"3

First non-repeating character is f
1
First non-repeating character is f
2"geeksforgeeks"4

First non-repeating character is f
7
First non-repeating character is f
5

=5"geeksforgeeks"3 index 59

First non-repeating character is f
0"geeksforgeeks"6

First non-repeating character is f
0
First non-repeating character is f
14
First non-repeating character is f
15 string 4
First non-repeating character is f
793

First non-repeating character is f
0string 6

First non-repeating character is f
7
First non-repeating character is f
797

First non-repeating character is f
7=60"geeksforgeeks""geeksforgeeks"4

First non-repeating character is f
7=0
First non-repeating character is f
672

First non-repeating character is f
7
First non-repeating character is f
1
First non-repeating character is f
807
First non-repeating character is f
2
First non-repeating character is f
2

=5

First non-repeating character is f
35

First non-repeating character is f
18
First non-repeating character is f
1
First non-repeating character is f
67

First non-repeating character is f
7
First non-repeating character is f
5

=5

First non-repeating character is f
35

First non-repeating character is f
18=9

First non-repeating character is f
18
First non-repeating character is f
822

First non-repeating character is f
0"geeksforgeeks"6

"geeksforgeeks"6

Python3

First non-repeating character is f
09
First non-repeating character is f
264

First non-repeating character is f
64
First non-repeating character is f
17
First non-repeating character is f
270
First non-repeating character is f
271

First non-repeating character is f
0
First non-repeating character is f
833=
First non-repeating character is f
97___

First non-repeating character is f
0
First non-repeating character is f
6
First non-repeating character is f
7
First non-repeating character is f
8
First non-repeating character is f
279
First non-repeating character is f
0
First non-repeating character is f
301
First non-repeating character is f
0
First non-repeating character is f
270
First non-repeating character is f
304

Các

=5

First non-repeating character is f
868string 09
First non-repeating character is f
0__

First non-repeating character is f
7
First non-repeating character is f
5
First non-repeating character is f
6

=5

First non-repeating character is f
868string 09
First non-repeating character is f
0__

First non-repeating character is f
0
First non-repeating character is f
327=
First non-repeating character is f
329

First non-repeating character is f
0
First non-repeating character is f
6
First non-repeating character is f
7
First non-repeating character is f
8
First non-repeating character is f
279
First non-repeating character is f
0
First non-repeating character is f
93
First non-repeating character is f
271

First non-repeating character is f
7
First non-repeating character is f
1
First non-repeating character is f
901=
First non-repeating character is f
25
First non-repeating character is f
271

=5

First non-repeating character is f
327=
First non-repeating character is f
348
First non-repeating character is f
909

First non-repeating character is f
0
First non-repeating character is f
1
First non-repeating character is f
912=__
First non-repeating character is f
367

First non-repeating character is f
7"geeksforgeeks"3
First non-repeating character is f
1
First non-repeating character is f
2

First non-repeating character is f
0
First non-repeating character is f
5
First non-repeating character is f
6

First non-repeating character is f
7"geeksforgeeks"3
First non-repeating character is f
354

First non-repeating character is f
270 = "geeksforgeeks"

First non-repeating character is f
929=
First non-repeating character is f
17
First non-repeating character is f
270
First non-repeating character is f
2

First non-repeating character is f
1
First non-repeating character is f
935=__
First non-repeating character is f
1
First non-repeating character is f
2
First non-repeating character is f
271

First non-repeating character is f
0
First non-repeating character is f
9
First non-repeating character is f
0
First non-repeating character is f
1
First non-repeating character is f
2

First non-repeating character is f
5
First non-repeating character is f
6

First non-repeating character is f
0
First non-repeating character is f
9
First non-repeating character is f
0=9
First non-repeating character is f
9
First non-repeating character is f
953
First non-repeating character is f
0
First non-repeating character is f
270
First non-repeating character is f
956

C#

string 1

First non-repeating character is f
96

First non-repeating character is f
14
First non-repeating character is f
11
First non-repeating character is f
12

First non-repeating character is f
0
First non-repeating character is f
14
First non-repeating character is f
15 =0
First non-repeating character is f
17
First non-repeating character is f
06 =06

First non-repeating character is f
0string 6

First non-repeating character is f
7=0
First non-repeating character is f
705

=5"geeksforgeeks"72

First non-repeating character is f
99 =0
First non-repeating character is f
978

First non-repeating character is f
7
First non-repeating character is f
6
First non-repeating character is f
0=0
First non-repeating character is f
610

=5

First non-repeating character is f
612

First non-repeating character is f
7
First non-repeating character is f
6
First non-repeating character is f
0=0
First non-repeating character is f
447

=5

First non-repeating character is f
1
First non-repeating character is f
620

First non-repeating character is f
18
First non-repeating character is f
622

=5"geeksforgeeks"6

=5

First non-repeating character is f
5 string 6

First non-repeating character is f
18
First non-repeating character is f
629

=5"geeksforgeeks"6

First non-repeating character is f
7"geeksforgeeks"6

First non-repeating character is f
7=0
First non-repeating character is f
755

First non-repeating character is f
7
First non-repeating character is f
6
First non-repeating character is f
0=0
First non-repeating character is f
24
First non-repeating character is f
25
First non-repeating character is f
719
First non-repeating character is f
93
First non-repeating character is f
764

=5

First non-repeating character is f
1
First non-repeating character is f
767
First non-repeating character is f
25
First non-repeating character is f
2

First non-repeating character is f
18
First non-repeating character is f
019

First non-repeating character is f
7"geeksforgeeks"6

First non-repeating character is f
7
First non-repeating character is f
1
First non-repeating character is f
776

=5"geeksforgeeks"3

First non-repeating character is f
1
First non-repeating character is f
2"geeksforgeeks"4

First non-repeating character is f
7
First non-repeating character is f
5

=5"geeksforgeeks"3 index 59

First non-repeating character is f
0"geeksforgeeks"6

First non-repeating character is f
0
First non-repeating character is f
14
First non-repeating character is f
15 string 4
First non-repeating character is f
793

First non-repeating character is f
0string 6

First non-repeating character is f
7=0
First non-repeating character is f
672

First non-repeating character is f
7=60"geeksforgeeks""geeksforgeeks"4

First non-repeating character is f
7=0
First non-repeating character is f
672

First non-repeating character is f
7
First non-repeating character is f
1
First non-repeating character is f
807
First non-repeating character is f
2
First non-repeating character is f
2

=5=67

First non-repeating character is f
18
First non-repeating character is f
1
First non-repeating character is f
67

First non-repeating character is f
7
First non-repeating character is f
5

=5=67

First non-repeating character is f
18=9

First non-repeating character is f
18
First non-repeating character is f
067

First non-repeating character is f
0"geeksforgeeks"6

"geeksforgeeks"6

First non-repeating character is f09 First non-repeating character is f264

First non-repeating character is f
55

First non-repeating character is f
64
First non-repeating character is f
17
First non-repeating character is f
270
First non-repeating character is f
271

string 6

First non-repeating character is f
0
First non-repeating character is f
833=
First non-repeating character is f
97___

First non-repeating character is f
0
First non-repeating character is f
081

First non-repeating character is f
0
First non-repeating character is f
6
First non-repeating character is f
7
First non-repeating character is f
8
First non-repeating character is f
279
First non-repeating character is f
0
First non-repeating character is f
301
First non-repeating character is f
0
First non-repeating character is f
270
First non-repeating character is f
304

First non-repeating character is f
7
First non-repeating character is f
612

Các

First non-repeating character is f
0string 6

First non-repeating character is f
7
First non-repeating character is f
1
First non-repeating character is f
098

First non-repeating character is f
7string 6

=5

First non-repeating character is f
102

First non-repeating character is f
7"geeksforgeeks"6

First non-repeating character is f
7
First non-repeating character is f
5

First non-repeating character is f
7string 6

=5

First non-repeating character is f
110

First non-repeating character is f
7"geeksforgeeks"6

First non-repeating character is f
0"geeksforgeeks"6

=5

First non-repeating character is f
868string 09
First non-repeating character is f
0__

First non-repeating character is f
0
First non-repeating character is f
6
First non-repeating character is f
0
First non-repeating character is f
076
First non-repeating character is f
122

First non-repeating character is f
7
First non-repeating character is f
1
First non-repeating character is f
644

=5

First non-repeating character is f
771

First non-repeating character is f
0"geeksforgeeks"6

First non-repeating character is f
0
First non-repeating character is f
1
First non-repeating character is f
132"geeksforgeeks"3
First non-repeating character is f
654

First non-repeating character is f
0
First non-repeating character is f
5 "geeksforgeeks"3 index 59

"geeksforgeeks"6

First non-repeating character is f
076
First non-repeating character is f
044

First non-repeating character is f
0=60"geeksforgeeks""geeksforgeeks"4

First non-repeating character is f
0
First non-repeating character is f
076
First non-repeating character is f
672

First non-repeating character is f
0____21
First non-repeating character is f
151

First non-repeating character is f
7
First non-repeating character is f
586
First non-repeating character is f
1
First non-repeating character is f
67

First non-repeating character is f
0
First non-repeating character is f
5

First non-repeating character is f
7
First non-repeating character is f
586=9
First non-repeating character is f
822

First non-repeating character is f
82

Đầ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 f
163
First non-repeating character is f
164
First non-repeating character is f
09
First non-repeating character is f
166

First non-repeating character is f
64
First non-repeating character is f
168

First non-repeating character is f
0
First non-repeating character is f
170=
First non-repeating character is f
172

First non-repeating character is f
0
First non-repeating character is f
6
First non-repeating character is f
7
First non-repeating character is f
8
First non-repeating character is f
9

Các

=5

First non-repeating character is f
3

string = "geeksforgeeks"

First non-repeating character is f
196

Đầ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.


Làm thế nào để bạn in ký tự không lặp lại đầu tiên từ chuỗi C?

Chương trình để tìm ký tự không lặp lại đầu tiên trong một chuỗi..
/ * C Chương trình để tìm ký tự không lặp lại đầu tiên */.
#include.
#include.
#Define no_of_chars 256 ..
int *get_char_count (char *str).
int *Count = (int *) calloc (sizeof (int), no_of_chars) ;.

Làm thế nào để tôi có được một ký tự không lặp lại trong một chuỗi?

Các ký tự không lặp lại là các ký tự chỉ có trong chuỗi một lần.Để tìm các ký tự không lặp lại trong một chuỗi, chúng tôi sẽ sử dụng một vòng để tính tần số của từng ký tự và in các ký tự có tần số đếm một lần sử dụng một vòng khác cho vòng lặp.

Làm thế nào để bạn có được ký tự duy nhất đầu tiên trong một chuỗi?

Để tìm chỉ mục của ký tự duy nhất đầu tiên có trong chuỗi đã cho, chúng ta có thể sử dụng HashMap.Ý tưởng là đi qua tất cả các ký tự của chuỗi và tạo một hashmap có khóa là ký tự và giá trị là sự xuất hiện của nó.use the hashmap. The idea is to go through all the characters of the string and create a hashmap with Key as the character and Value as its occurrences.

Làm thế nào để tôi tìm thấy ký tự không lặp lại đầu tiên trong một chuỗi trong CPP?

Hãy xem các bước để giải quyết vấn đề ...
Khởi tạo chuỗi ..
Khởi tạo một bản đồ char và mảng để lưu trữ tần số của các ký tự trong chuỗi ..
Lặp lại chuỗi ..
Tìm tần số của từng ký tự và lưu trữ chúng trong bản đồ ..
Lưu trữ chỉ số của nhân vật là tốt ..