535. Encode and Decode TinyURL
来源:互联网 发布:制作电子报刊的软件 编辑:程序博客网 时间:2024/05/21 04:40
import base64
class Codec:
def encode(self, longUrl):
"""Encodes a URL to a shortened URL.
:type longUrl: str
:rtype: str
"""
bytesString = longUrl.encode(encoding="utf-8")
encodestr = base64.b64encode(bytesString)
return 'http://tinyurl.com/' + encodestr
def decode(self, shortUrl):
"""Decodes a shortened URL to its original URL.
:type shortUrl: str
:rtype: str
"""
decodestr = base64.b64decode(shortUrl.split('http://tinyurl.com/')[1])
class Codec:
def encode(self, longUrl):
"""Encodes a URL to a shortened URL.
:type longUrl: str
:rtype: str
"""
bytesString = longUrl.encode(encoding="utf-8")
encodestr = base64.b64encode(bytesString)
return 'http://tinyurl.com/' + encodestr
def decode(self, shortUrl):
"""Decodes a shortened URL to its original URL.
:type shortUrl: str
:rtype: str
"""
decodestr = base64.b64decode(shortUrl.split('http://tinyurl.com/')[1])
return decodestr
编解码一个url地址,这里用base64加密
阅读全文
0 0
- 535. Encode and Decode TinyURL
- 535. Encode and Decode TinyURL
- 535. Encode and Decode TinyURL
- 535. Encode and Decode TinyURL
- 535. Encode and Decode TinyURL
- 535. Encode and Decode TinyURL
- 535. Encode and Decode TinyURL
- 535. Encode and Decode TinyURL
- 535. Encode and Decode TinyURL
- 535. Encode and Decode TinyURL
- 535. Encode and Decode TinyURL
- Encode and Decode TinyURL
- Encode and Decode TinyURL
- Encode and Decode TinyURL
- leetcode题解-535. Encode and Decode TinyURL
- 【LeetCode】535. Encode and Decode TinyURL
- LeetCode:535. Encode and Decode TinyURL
- Leetcode 535. Encode and Decode TinyURL
- Fragment+viewPager
- js,css加时间戳
- Another reason for Xtrabackup error “log block numbers mismatch”
- linux之nfs的配置和使用
- MonggoDB开关服务的个人小笔记
- 535. Encode and Decode TinyURL
- Qt5 C++源码中使用中文的简单步骤
- Web Service 之 WSDL文件讲解
- 【Linux】shell脚本下的命令代换` `和$() 以及eval
- android应用的签名及混淆
- Oracle Database PSU/CPU
- iOS 中文转拼音
- php HttpRequest类
- 信号屏蔽与信号递达