Skip to content

Task16#820

Open
AlexAnderViktor wants to merge 2 commits intoKFalcon2022:masterfrom
AlexAnderViktor:Task16
Open

Task16#820
AlexAnderViktor wants to merge 2 commits intoKFalcon2022:masterfrom
AlexAnderViktor:Task16

Conversation

@AlexAnderViktor
Copy link

No description provided.

@KFalcon2022 KFalcon2022 self-assigned this Feb 17, 2025
newArr[0] = arr[i];
}
else {
newArr[i+1] = arr[i];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

потеряны пробелы до и после +

if (i == arr.length - 1) {
newArr[0] = arr[i];
}
else {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else располагается на той же строке, что и }

int[] result = new int[arr.length - 1];

for (int i = 0, j = 0; i < arr.length; i++) {
if (i != index){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

потерян пробел после )

static boolean isEqualSize(int[] arr1, int[] arr2) {
// Ваш код

if (arr1 != null && arr2 != null && arr1.length > 0 && arr2.length > 0 && arr1.length == arr2.length) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Если arr1.length > 0 && arr1.length == arr2.length, может ли arr2.length == 0? Лишнее условие

result[i] = value1 * value2;
}

return result;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Если цикл довести до конца короткого массива - будет тот же эффект, т.к. элементы по умолчанию инициализируются нулями, а любое умножение на 0 даст в результате 0

return 0;
int maxIndex = -1;

for (int i = 0; i < arr.length; i++) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не проще просто массив с конца перебирать? избежишь лишних операций

int count = 0;

for (int i = 0; i < arr.length; i++) {
boolean toRemove = false;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isRemoving?

boolean toRemove = false;

for (int j = 0; j < removingValues.length; j++) {
if (arr[i] == removingValues[j]) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

у тебя же есть isContains(). Зачем ту же, фактически, функиональность заново реализовывать?

* При этом индексы элементов могут не совпадать.
*/

public static void bubbleSort(int[] arr) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это разве отсюда?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Увидел. Но идея плохая: [1,1,1,1,2], [1,2,2,2,2]. Твое решение вернет false, хотя по условию должно быть true

int[] newArr = new int[arr.length];

for (int i = 0; i < arr.length; i++) {
if (i == arr.length - 1) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

зачем в каждой итерации делать проверку, если мы еще до цикла можем поместить последний элемент исходного массива на нулевой индекс результирующего? И просто учесть это в условии цикла

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments