<commit_before>"""Leetcode 201. Bitwise AND of Numbers Range
Medium

URL: https://leetcode.com/problems/bitwise-and-of-numbers-range/

Given a range [m, n] where 0 <= m <= n <= 2147483647,
return the bitwise AND of all numbers in this range, inclusive.

Example 1:
Input: [5,7]
Output: 4

Example 2:
Input: [0,1]
Output: 0
"""


class Solution(object):
    def rangeBitwiseAnd(self, m, n):
        """
        :type m: int
        :type n: int
        :rtype: int
        """
        if m == 0:
            return 0

        result = m
        for i in range(m + 1, n + 1):
            result &= i
        return result


def main():
    # Output: 4
    m, n = 5, 7
    print Solution().rangeBitwiseAnd(m, n)

    # Output: 0
    m, n = 0, 1
    print Solution().rangeBitwiseAnd(m, n)


if __name__ == '__main__':
    main()<commit_msg>Revise class name and add time/space complexity<commit_after>"""Leetcode 201. Bitwise AND of Numbers Range
Medium

URL: https://leetcode.com/problems/bitwise-and-of-numbers-range/

Given a range [m, n] where 0 <= m <= n <= 2147483647,
return the bitwise AND of all numbers in this range, inclusive.

Example 1:
Input: [5,7]
Output: 4

Example 2:
Input: [0,1]
Output: 0
"""


class SolutionBruteForce(object):
    def rangeBitwiseAnd(self, m, n):
        """
        :type m: int
        :type n: int
        :rtype: int

        Time limit exceeded.

        Time complexity: O(n-m).
        Space complexity: O(1).
        """
        if m == 0:
            return 0

        result = m
        for i in range(m + 1, n + 1):
            result &= i
        return result


def main():
    # Output: 4
    m, n = 5, 7
    print SolutionBruteForce().rangeBitwiseAnd(m, n)

    # Output: 0
    m, n = 0, 1
    print SolutionBruteForce().rangeBitwiseAnd(m, n)


if __name__ == '__main__':
    main()
{'fraction_non_alphanumeric': 0.12609170305676856, 'fraction_numerical': 0.035480349344978165, 'mean_word_length': 2.144082332761578, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '4109214', 'n_tokens_mistral': 694, 'n_tokens_neox': 622, 'n_words': 212}