比较排序的次数 package com.huike.service; public class Test { public static void main(String[] args){ System.out.println(new Test().a("123 321 522")); } public int a(String inData){ String [] a = inData.split(" "); int count=0; int [] aa = new int[a.length]; for (int m=0;m<a.length;m++){ aa[m]= Integer.parseInt(a[m]); } for (int i =0;i<aa.length-1;i++){ int min=aa[i]; if(aa[i+1] < min){ int t = min; aa[i] =aa[i+1]; aa[i+1] = t; count++; } if(i>0){ if(aa[i-1]>aa[i]){ int temp = aa[i-1]; aa[i-1] = aa[i]; aa[i] = temp; count++; } } } return count; } }
2020神州信息笔试算法题
最新推荐文章于 2024-08-11 21:49:29 发布