Skip to content

Conversation

@stillwearit
Copy link

No description provided.

@KFalcon2022 KFalcon2022 self-assigned this Feb 4, 2025
int[] basketsArray = new int[basketsAmount];

for (int i = 0; i < basketsArray.length; i++) {
basketsArray[i] = Character.getNumericValue(baskets.charAt(i));
Copy link
Owner

Choose a reason for hiding this comment

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

Стоит ли вообще тратить ресурсы на конвертацию символов в числа? Какая разница, валидировать 0 и 1 или '0' и '1'?

actionsAmount[i] += basketsArray[left] * (i - left);
}

for (int right = i + 1; right < actionsAmount.length; right++) {
Copy link
Owner

Choose a reason for hiding this comment

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

есть четкое ощущение, что использование модуля (Math.abs()) избавит тебя от необходимости использовать два последовательных цикла и делить корзинки на правые и левые

@stillwearit
Copy link
Author

Спасибо, исправила!

Copy link
Owner

@KFalcon2022 KFalcon2022 left a comment

Choose a reason for hiding this comment

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

Мелкое замечание, задача зачтена

if (!isValid(basketsArray[i])) {
return new int[]{};
}
}
Copy link
Owner

Choose a reason for hiding this comment

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

Логичнее было бы все, вместе с циклом, вынести в boolean-метод isValid(). И если результат false - возвращать пустой массив. Но текущий вариант тоже имеет право на жизнь

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