<commit_before>import unittest
import utils


# O(n) time. O(1) space. Iteration.
class Solution(object):
    def isToeplitzMatrix(self, matrix):
        """
        :type matrix: List[List[int]]
        :rtype: bool
        """
        rows = len(matrix)
        cols = len(matrix[0])
        start_row = rows - 1
        start_col = 0

        for _ in xrange(rows + cols - 1):
            num = matrix[start_row][start_col]
            row = start_row + 1
            col = start_col + 1

            while row < rows and col < cols:
                if matrix[row][col] != num:
                    return False
                row += 1
                col += 1

            if start_row > 0:
                start_row -= 1
            else:
                start_col += 1

        return True


class Test(unittest.TestCase):
    def test(self):
        cases = utils.load_json_from_path('../leetcode_test_cases/p766.json').test_cases

        for case in cases:
            actual = Solution().isToeplitzMatrix(case.matrix)
            self.assertEqual(case.expected, actual)


if __name__ == '__main__':
    unittest.main()<commit_msg>766. Toeplitz Matrix<commit_after>import unittest
import utils


# O(n) time. O(1) space. Iteration.
class Solution(object):
    def isToeplitzMatrix(self, matrix):
        """
        :type matrix: List[List[int]]
        :rtype: bool
        """
        for row in xrange(len(matrix) - 1):
            for col in xrange(len(matrix[0]) - 1):
                if matrix[row][col] != matrix[row + 1][col + 1]:
                    return False
        return True


class Test(unittest.TestCase):
    def test(self):
        cases = utils.load_json_from_path('../leetcode_test_cases/p766.json').test_cases

        for case in cases:
            actual = Solution().isToeplitzMatrix(case.matrix)
            self.assertEqual(case.expected, actual)


if __name__ == '__main__':
    unittest.main()
{'fraction_non_alphanumeric': 0.11277806518365235, 'fraction_numerical': 0.01396792550439731, 'mean_word_length': 1.8151382823871907, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5748035', 'n_tokens_mistral': 618, 'n_tokens_neox': 583, 'n_words': 141}