mirror of
https://github.com/donnemartin/system-design-primer.git
synced 2025-12-14 17:08:56 +03:00
Merge 1657d2fdae into 40d5d2edcc
This commit is contained in:
@@ -133,11 +133,11 @@ To generate the unique url, we could:
|
|||||||
```python
|
```python
|
||||||
def base_encode(num, base=62):
|
def base_encode(num, base=62):
|
||||||
digits = []
|
digits = []
|
||||||
while num > 0
|
while num > 0:
|
||||||
remainder = modulo(num, base)
|
num, remainder = divmod(num, base)
|
||||||
digits.push(remainder)
|
digits.append(remainder)
|
||||||
num = divide(num, base)
|
digits.reverse()
|
||||||
digits = digits.reverse
|
return digits
|
||||||
```
|
```
|
||||||
|
|
||||||
* Take the first 7 characters of the output, which results in 62^7 possible values and should be sufficient to handle our constraint of 360 million shortlinks in 3 years:
|
* Take the first 7 characters of the output, which results in 62^7 possible values and should be sufficient to handle our constraint of 360 million shortlinks in 3 years:
|
||||||
|
|||||||
Reference in New Issue
Block a user