[英]BigInteger Sorting, Complexity O(n)
function 'bigSorting' 将 BigInteger 输入作为“字符串列表”。 我有一个单一的循环方法来对给定复杂度的字符串列表进行排序,但仍然没有对字符串进行排序/BigInteger 列表没有排序。
输入:(字符串列表)31415926535897932384626433832795, 1, 3, 10, 3, 5
public static List<String> bigSorting(List<String> u) {
// Write your code here
String S = "";
for(int i = 0; i<u.size()-1; i++)
{
BigInteger a = new BigInteger(u.get(i));
BigInteger b = new BigInteger(u.get(i+1));
int x = a.compareTo(b);
if(x>1)
{
S = u.get(i);
u.set(i,u.get(i+1));
u.set(i+1,S);
i = -1;
}
}
return u;
}
OUTPUT:(错误答案)31415926535897932384626433832795、1、3、10、3、5
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.