How do you remove the duplicate characters in a given string without using any additional buffer.
2011-04-28 13:03
701 查看
void removeDuplicates(char* str) { if (!str) return; int len = strlen(str); if (len < 2) return; int tail=1; int j=0; for(int i = 1; i < len; i++) { for(j = 0; j < tail; j++) { if(str[i] == str[j]) break; } if(tail == j) str[tail++] = str[i]; } str[tail] = '0'; }
终于搞明白是怎么回事情了,其实tail是一个point,来表示现在从左边数起第几个是需要check的,如果发现重复的,i 就继续往后走,tail不动。其实就是tail之前的所有的值都是不重复的,后面慢慢check.
相关文章推荐
- CH1-3: remove duplicate char in a string, with/without additional buffer
- How do you get the length of a string in jQuery?
- 【3】Remove the duplicate characters in a string
- [CrackCode] 1.3 Remove the duplicate characters in a string
- How do you copy the contents of an array to a std::vector in C++ without looping? (From stack over flow)
- string - How to get the filename without the extension from a path in Python? - Stack Overflow
- 【摘录】How do you change the drawing order of views in Android?
- 如何在参考文献中优雅地引用URL?How do you get nicely formatted URLs in the bibliography?
- How do you check if a variable is an array in JavaScript? [duplicate]
- Find the longest substring with k unique distinct characters in a given string (Google)
- ChipScope - For the ChipScope flows, how do you get the signal names into the Analyzer without manually adding them?
- LeetCode : Given a string, find the length of the longest serial substring without repeating characters.
- How to upload a file via a HTTP multipart request in Java without using any external libraries
- //Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the in
- 【MySQL笔记】解除输入的安全模式,Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode, toggle the option in Preferences -> SQL Queries and reconnect.
- How do I import a new Java CA cert without using the keytool command line utility?
- how to do with the special characters in the xml data
- rror Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode, toggle the option in Preferences -> SQL Editor and reconnec
- CareerCup Given a dictionary, how would you add spaces in this string
- Bubble Gum, Bubble Gum, in the dish, how many pieces do you wish?”