-
Notifications
You must be signed in to change notification settings - Fork 226
Task13 #817
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
base: master
Are you sure you want to change the base?
Task13 #817
Conversation
| int stepsCount = 0; | ||
| int leftover = wateringCanVolume; | ||
| for (int i = 0; i < plants.length; i++) { | ||
| if (plants[i] < 1 || plants[i] > wateringCanVolume) { |
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.
уже писал - валидацию и логику стоит разделять
| return -1; | ||
| } | ||
|
|
||
| if (leftover >= plants[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.
этот if-else можно упростить. Фактически, ты все описал верно. Но есть мнение, что увеличение шага на один и затраты на полив происходят всегда (на каждой итерации цикла). И лишь дополнительными действиями являются поход к реке и наполнение лейки. То есть тут фактически нет разветвления на два сценария, есть лишь небольшой крюк при определенном условии:)
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.
Вроде бы поняла, спасибо!
| return stepsCount; | ||
| } | ||
|
|
||
| static boolean isValid (int plant, int wateringCanVolume) { |
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.
лишний пробел после имени метода
| int stepsCount = 0; | ||
| int leftover = wateringCanVolume; | ||
| for (int i = 0; i < plants.length; i++) { | ||
| if (!isValid(plants[i], wateringCanVolume)) { |
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.
валидация все еще не выдела из логики. Где гарантия, что на plants[plants.length - 1] мы не обнаружим не валидное число? Получится, что все итерации до этого затратили лишние ресурсы процессора
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.
думала, лучше всё одним циклом сделать, теперь понимаю, почему не лучше 😄
| stepsCount += i * 2; | ||
| leftover = wateringCanVolume - plants[i]; | ||
| } | ||
| stepsCount += 1; |
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.
кажется, табуляция поплыла
No description provided.