---
# System prepended metadata

title: CSPT23 Lecture 5

---

# CSPT23 Lecture 5
## [To Lower Case](https://leetcode.com/problems/to-lower-case/)
```
class Solution:
    """
    LambdaSchool --> lambdaschool
    AarOn BuRnS --> aaron burns
    H3ll0 --> h3ll0
    
    Hint 1: all upper-case letters have encoding values > 64 and < 91
    Hint 2: the lower-case equivalent of an upper-case character
    is the upper-case character's encoding +32
    Hint 3: you can use ord(x) to get the encoding value of a character x
    you can use chr(x) to convert back to a character
    
    Plan
    Go through each character and if that character's encoding is between the correct range, then add 32 to it
    to get the lower-case equivalent. Else don't do anything to that character
    """
    def toLowerCase(self, s: str) -> str:
        res = ""
        for char in s:
            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:
    """
    n = 15 --> 1111
    output = 4
    
    n = 0 --> 00000
    output = 0
    
    n = 1 --> ....001
    output = 1
    
    Hint: You can use bin(x) to get a binary string representation of the number x
    bin(15) --> '00000000....1111'
    """
    def hammingWeight(self, n: int) -> int:
        return bin(n).count('1')
```