Skip to content

Commit cd60c39

Browse files
authored
Merge pull request TheAlgorithms#722 from Egoscio/patch-1 to fix TheAlgorithms#719
Made Matrix equality comparison deep.
2 parents 5a934c1 + 10932cc commit cd60c39

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

DataStructures/Matrix/Matrix.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,15 @@ public Matrix multiply(Matrix other) throws RuntimeException {
211211
* @return boolean
212212
*/
213213
public boolean equals(Matrix other) {
214-
return this == other;
214+
if (this.getRows() != other.getRows() || this.getColumns() != other.getColumns())
215+
return false;
216+
217+
for (int i = 0; i < this.data.length; i++)
218+
for (int j = 0; j < this.data[0].length; j++)
219+
if (this.data[i][j] != other.data[i][j])
220+
return false;
221+
222+
return true;
215223
}
216224

217225
/**

0 commit comments

Comments
 (0)