I think that all we need is
if (matrix.length == 0)
However, I saw some of them write
if (matrix == null || matrix.length == 0 || matrix[0].length == 0)
Is my version enough to check a matrix is empty or not or we need to write the above version?
You will get a NullPointerException
if you call matrix.length()
if matrix is null, that's why the second check is better.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With