/
Ersh
/
Homewok6
Обзор
Документация
Войти
/
Ersh
/
Homewok6
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Homework6/src/LazyString.java
62 строки
2 KB
Ersh
upload files
04 дек 2025, 12:19
04 дек 2025, 12:19
5dd1e1a
Код
Авторство
О чём код?
public class LazyString { private String source; private int start, end; private int hash; private LazyString() {} public LazyString(String source, int start, int end) { this.source = source; this.start = start; this.end = end; this.hash = 0; for (int i = start; i < end; i++) { this.hash += source.charAt(i); } } public LazyString shiftRight() { LazyString shifted = new LazyString(); shifted.source = this.source; shifted.start = this.start + 1; shifted.end = this.end + 1; char removedChar = this.source.charAt(this.start); char addedChar = this.source.charAt(this.end); shifted.hash = this.hash - removedChar + addedChar; return shifted; } public int length() { return end - start; } public boolean equals(LazyString that) { if (this.length() != that.length()) { return false; } for (int i = 0; i < this.length(); i++) { if (this.source.charAt(this.start + i) != that.source.charAt(that.start + i)) { return false; } } return true; } @Override public int hashCode() { return hash; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; LazyString that = (LazyString) o; return this.equals(that); } }