<新浪微博笔试2>判断字符数组中所有字符只出现一次

<新浪微博笔试2>判断字符数组中所有字符只出现一次 

package lzl.bishi;

import java.util.Scanner;

public class Wb02 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String str=sc.nextLine();
        System.out.println(solve(str.toCharArray()));
    }
    public static boolean solve(char[] strs){
        if(strs==null||strs.length==0) return true;
        hps(strs);
        for (int i = 1; i -1 ; i--) {

            adj(strs,i,len);

        }
        for (int i = len-1; i >-1 ; i--) {
            swap(strs,i,0);
            adj(strs,0,i);
        }
    }
    private static  void adj(char[] strs,int p,int size){
        
        for (int i = p; i strs[max]) max=r;
                if(max!=i) swap(strs,i,max);
            }else break;
        }

    }

    private static  void swap(char[] nums,int a,int b){
        char t=nums[a];
        nums[a]=nums[b];
        nums[b]=t;
    }

}

 

你可能感兴趣的:(面试笔试,判断字符数组,中所有字符只出现一次)