作者归档:在线疯狂

RSS feed of 在线疯狂

[LeetCode]License Key Formatting

题目描述:

LeetCode 482. License Key Formatting

Now you are given a string S, which represents a software license key which we would like to format. The string S is composed of alphanumerical characters and dashes. The dashes split the alphanumerical ...

继续阅读

[LeetCode]Magical String

题目描述:

LeetCode 481. Magical String

A magical string S consists of only '1' and '2' and obeys the following rules:

The string S is magical because concatenating the number of contiguous occurrences of characters '1' and '2' generates the string ...

继续阅读

[LeetCode]Number Complement

题目描述:

LeetCode 476. Number Complement

Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation.

Note:

  1. The given integer is guaranteed to fit within the range of a 32-bit signed ...

继续阅读

Python Requests实现短网址还原

利用python-requests(http://www.python-requests.org/),只需数行代码即可实现短网址还原。

通过HTTP HEAD请求,从返回响应的头信息(headers)中取出Location字段即为短网址对应的原始网址。

Python代码:

import requests
def revertShortLink(url):
    res = requests.head(url)
    return res.headers.get('location')

代码测试:

print revertShortLink('http://t.cn/RVMAn7W')

返回结果:

https://bookshadow.com/weblog/2016/10/15/leetcode-maximum-xor-of-two-numbers-in-an-array/#0-tsina-1-85154-397232819ff9a47a7b7e80a40613cfe1