Код: Выделить всё
class Solution {
public:
vector rearrangeArray(vector& num) {
int n = num.size();
vector ans(n);
vector pos(n / 2);
vector neg(n / 2);
int index = 0;
while (index < num.size()) {
if (num[index] > 0) {
pos.push_back(num[index]);
} else if (num[index] < 0) {
neg.push_back(num[index]);
}
index++;
}
for (int i = 0; i < num.size() / 2; i++) {
ans[2 * i] = pos[i];
ans[2 * i + 1] = neg[i];
}
return ans;
}
};
nums =
[3,1,-2,-5,2,-4]
почему выводится
[0,0,0,0,0,0]
Это должно быть [3,-2,1,-5,2,-4]
Пожалуйста, помогите мне решить мой код
Подробнее здесь: https://stackoverflow.com/questions/787 ... -sign-in-c