C語言字串 陣列去重

2021-10-25 08:43:59 字數 807 閱讀 2375

輸入: hello 輸出: helo

第一種實現: 不新開陣列, 也就是原地去重.

#include #include void removeduplicate(char str);

int main (void)

void removeduplicate(char str)

void removeduplicate(char str, char res)

void removeduplicate(char str) ;

int p = 0;

int i;

for (i=0; i第四種, 也是新開ascii陣列進行標記, 實現去2重, 比如輸入: sswqswww, 輸出: sswqsw

#include #include void removeduplicate(char str);

int main (void)

void removeduplicate(char str) ;

int p = 0;

int i;

for (i=0; i第五種, 上面的**簡單改下, 既可以實現去n重

#include #include void removeduplicate(char str, int n)

int main (void)

void removeduplicate(char str, int n) ;

int p = 0;

int i;

for (i=0; i}

str[p] = '\0';

}

字串陣列去重

這裡只考慮最簡單字串的陣列去重,暫不考慮,物件,函式,nan等情況,這種用正則實現起來就吃力不討好了。非正則實現 es6實現 let str arr b c 1,a 3,v 2 e 6 g 9 arr 9,hello 6 9 1 2,6,b c function unique arr console...

js 陣列 字串 去重

array.prototype.unique1 function return n array.prototype.unique2 function r n為hash表,r為臨時陣列 for var i 0 i this.length i 遍歷當前陣列 return r array.prototyp...

2 陣列 字串去重

今天說的陣列和字串去重呢,主要用到es6新的資料結構set,它類似於陣列,但是成員的值都是唯一的,沒有重複的值,所以活用set來進行陣列和字串的去重。1.首先簡單介紹下set的用法 set本身是乙個建構函式,用來生成 set 資料結構。set函式可以接受乙個陣列 或者具有 iterable 介面的其...