相关疑难解决方法(0)

如何按字母顺序对字符串java进行排序

我想按字母顺序对JAVA中的字符串进行排序,如下所示,大写字母和小写字母跟随AaBbCcDdEeFfGg.例如,如果我把AbaC归还给我AabC谢谢!!

java alphabetical

10
推荐指数
2
解决办法
8万
查看次数

如何在O(n)时间内检查两个字符串是否相互排列?(Java)的

我写了这个类,可以检查两个给定的字符串是否是彼此的排列.但是,据我所知,这是在O(n ^ 2)时间运行,因为string.indexOf()在O(n)时间运行.

如何提高这项计划的效率?

import java.util.*;

public class IsPermutation{
   public void IsPermutation(){
      System.out.println("Checks if two strings are permutations of each other.");
      System.out.println("Call the check() method");
   }

   public boolean check(){
      Scanner console = new Scanner(System.in);
      System.out.print("Insert first string: ");
      String first = console.nextLine();
      System.out.print("Insert second string: ");
      String second = console.nextLine();

      if (first.length() != second.length()){
         System.out.println("Not permutations");
         return false;
      }

      for (int i = 0; i < first.length(); i++){
         if (second.indexOf(first.charAt(i)) == -1){
            System.out.println("Not permutations");
            return false;
         } 
      }
      System.out.println("permutations");
      return …
Run Code Online (Sandbox Code Playgroud)

java algorithm

1
推荐指数
2
解决办法
2466
查看次数

标签 统计

java ×2

algorithm ×1

alphabetical ×1