我正在尝试在代码战中解决此问题。 https://www.codewars.com/kata/are-they-the-same/
我写了以下代码。
fn comp(mut a: Vec<i64>,mut b: Vec<i64>) -> bool {
a.sort();
b.sort();
a = a.iter().map(|x| x * x).collect();
a == b
}
法官系统说有一个输入,我的代码返回false,但应为true。我不明白是什么问题。
我看到了通过所有测试的其他人的答案。这就是其中之一。
fn comp(a: Vec<i64>,b: Vec<i64>) -> bool {
let mut a1 = a.iter().map(|&x| x * x).collect::<Vec<_>>();
let mut a2 = b;
a1.sort();
a2.sort();
a1 == a2
}
平方和排序的顺序很重要吗?