---
# System prepended metadata

title: CSPT21 Lecture 5

---

# CSPT21 Lecture 5
## [To Lower Case](https://leetcode.com/problems/to-lower-case/)
```
class Solution:
    """
    Understand
    "LambdaSchool" --> "lambdaschool"
    "NiCk WatSon" --> "nick watson"
    "H3LL0" --> "h3ll0"
    
    Plan
    Hint 1: all upper-case letters encoding have value > 64 AND < 91
    Hint 2: the lower-case equivalent of an upper-case character is it's encoding +32
    Hint 3: you can use ord(x) to get the encoding value of a character.
    You can use chr(x) to convert back to a character.
    
    Create a new string from the input string, but make sure to append only lower-case characters. We know we have an upper-case character if the encoded value is 64 < x < 91. Return
    newly created string.
    
    Runtime: O(n)
    Space: O(n)
    """
    def toLowerCase(self, str: str) -> str:
        res = ""
        for char in str:
            encodedValue = ord(char)
            if 64 < encodedValue < 91:
                res += chr(encodedValue + 32)
            else:
                res += char
        return res
```
## [Number of 1 bits](https://leetcode.com/problems/number-of-1-bits/)
```
class Solution:
    """
    00000000000000000000000000001011 (11) --> 3
    00000000000000000000000010000000 (128) --> 1
    00000000000000000000000000000000 (0) --> 0
    
    bin(11) --> '00000000000000000000000000001011'
    
    Use bin() to get string representation of number. Walk the string and count 
    how many 1s you see.
    n = 2 str(n) --> "2"
    bin(n) --> "10"
    """
    def hammingWeight(self, n: int) -> int:
        return bin(n).count('1')
```