去除字符串中的重复字符,对于出现超过2次(包含2次)的字符,只保留第一个。 例:输入abcbdde,输出abcde。
示例1
输入
"abcbdde"
输出
"abcde"
备注:
不使用集合类、字符串contains等功能。
加载中...
import java.util.*; public class Solution { /** * * @param str string字符串 * @return string字符串 */ public String removeDuplicatedChars (String str) { // write code here } }
class Solution { public: /** * * @param str string字符串 * @return string字符串 */ string removeDuplicatedChars(string str) { // write code here } };
# # # @param str string字符串 # @return string字符串 # class Solution: def removeDuplicatedChars(self , str ): # write code here
/** * * @param str string字符串 * @return string字符串 */ function removeDuplicatedChars( str ) { // write code here } module.exports = { removeDuplicatedChars : removeDuplicatedChars };
# # # @param str string字符串 # @return string字符串 # class Solution: def removeDuplicatedChars(self , str ): # write code here
package main /** * * @param str string字符串 * @return string字符串 */ func removeDuplicatedChars( str string ) string { // write code here }
/** * * @param str string字符串 * @return string字符串 */ char* removeDuplicatedChars(char* str ) { // write code here }
"abcbdde"
"abcde"