Naive Approach
Removing duplicate letter from a String
------------------------------------------------
Removing duplicate letter from a String
------------------------------------------------
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
#include<string.h> #include<stdio.h> char str[] = "ncertcppblogger" ; void shift( int i){ do { str[i]=str[i+1]; i++; } while (str[i]!= '\0' ); } void removeDups(){ int i,j; for (i=0;i< strlen (str);i++){ for (j=i+1;j< strlen (str);j++){ if (str[i]==str[j]){ shift(j); j=i+1; } } } printf ( "%s" ,str); } int main(){ removeDups(); return 0; }
OUTPUT
ncertpblog
RUN THIS
HASHING APPROACH
Complexity O(n) ----------------
RUN THIS |