-
Notifications
You must be signed in to change notification settings - Fork 226
Task12 #813
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Task12 #813
Conversation
| int[] basketsArray = new int[basketsAmount]; | ||
|
|
||
| for (int i = 0; i < basketsArray.length; i++) { | ||
| basketsArray[i] = Character.getNumericValue(baskets.charAt(i)); |
There was a problem hiding this comment.
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++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
есть четкое ощущение, что использование модуля (Math.abs()) избавит тебя от необходимости использовать два последовательных цикла и делить корзинки на правые и левые
|
Спасибо, исправила! |
KFalcon2022
left a comment
There was a problem hiding this 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[]{}; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Логичнее было бы все, вместе с циклом, вынести в boolean-метод isValid(). И если результат false - возвращать пустой массив. Но текущий вариант тоже имеет право на жизнь
No description provided.