Skip to content

kotlin 4 hw #57

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

VadimBoz
Copy link

@VadimBoz VadimBoz commented Mar 1, 2025

No description provided.

override fun equals(other: Any?): Boolean {
if (other == null) return false
if (this === other) return true
if (other is List<*> && (other as List<*>)[0] is Int && (other as List<*>).size == size) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Мне кажется, тут слишком подробно и можно сократить до сравнения размеров и потом поэлементного сравнения с ранним выходом. contains - довольно дорогая операция тут получается, так как на каждый элемент обходится вся коллекция. А нам нужно сравнить порядок элементов и их значение. Если по значению элементы совпадают, но порядок у них разный - списки не считаются равными!

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