Check for Symmetry
EasyP3Coding
A matrix is symmetric if it is equal to its own transpose: the entry at row i, column j equals the entry at row j, column i for every pair. Return true if matrix is symmetric and false otherwise.
A matrix that is not square (the number of rows differs from the number of columns) is not symmetric.
Example 1
- Input
- matrix = [[1,2],[2,1]]
- Output
- true
Example 2
- Input
- matrix = [[1,2],[3,1]]
- Output
- false
Example 3
- Input
- matrix = [[5]]
- Output
- true
Constraints
- 1 <= rows, cols <= 100
- -10^9 <= matrix[i][j] <= 10^9
- All rows have the same length.
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 12. ⌘Enter runs, ⌘⇧Enter submits.