删除重复元素

https://www.nowcoder.com/questionTerminal/c4ea1f2263434861aef111aa44a5b064

import java.util.Scanner;

public class Main{
    
    public static void main(String[] args){
        
        Scanner in = new Scanner(System.in);
        
        while(in.hasNextLine()){
             String str = in.nextLine();
            StringBuffer res = sub(str);
            System.out.println(res);
        }
        
    }
    
    public static StringBuffer sub(String str){
        
        int arr[] = new int[27];
        StringBuffer res = new StringBuffer();
        for( int i=0; i < str.length(); ++i ){
            
            if( arr[str.charAt(i)-'a'] == 0 ){
                res.append(str.charAt(i));
            }
              arr[str.charAt(i)-'a']++;
        }
        
        return res;
    }
    
}

 

posted @ 2019-03-11 10:01  清湾大威少  阅读(110)  评论(0编辑  收藏  举报