# CSPT17 Lecture 4 - Memory Basics
## [ToLowerCase](https://leetcode.com/problems/to-lower-case/)
```
class Solution:
"""
Understand
"HELLO" --> "hello"
"hElLo" --> "hello"
"hEllo1" --> "hel lo1"
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
go through each character in the original string
if character is an upper-case character, the lower-case character is + 32
return the new string that we just created
Runtime: O(n)
Space: O(n)
"""
def toLowerCase(self, str: str) -> str:
encodedChars = [ord(x) for x in str]
for i in range(len(encodedChars)):
if encodedChars[i] > 64 and encodedChars[i] < 91:
encodedChars[i] += 32
decodedChars = [chr(x) for x in encodedChars]
return ''.join(decodedChars)
```
## [Hamming Weight](https://leetcode.com/problems/number-of-1-bits/)
```
class Solution:
"""
Hint: You can use bin(n) to get the string representation of
the binary equivalent for a number
Understand
0 -> 0
1 -> 1
2 "10"-> 1
Plan
Convert number to string, then walk through string and count 1s
Runtime: O(1)
Space: O(1)
"""
def hammingWeight(self, n: int) -> int:
return bin(n).count('1')
```