Match Preview: Player E vs. Player F
This all-local matchup is set to be one of tomorrow’s highlights:
<|repo_name|>nicoguaro/coinbase<|file_sep|>/coinbase/client.py
import os
import json
import hmac
import time
import hashlib
from datetime import datetime
from coinbase import errors
API_BASE_URL = 'https://api.exchange.coinbase.com'
API_VERSION = 'v1'
class CoinbaseClient(object):
def __init__(self,
key=None,
secret=None,
api_base_url=API_BASE_URL,
api_version=API_VERSION):
self.key = key
self.secret = secret
self.api_base_url = api_base_url
self.api_version = api_version
def _get_endpoint(self):
return "{}/{}".format(self.api_base_url.rstrip('/'), self.api_version)
def _build_headers(self):
headers = {
'CB-ACCESS-KEY': self.key,
'CB-ACCESS-SIGN': self._generate_signature(),
'CB-ACCESS-TIMESTAMP': self._generate_timestamp(),
'CB-ACCESS-PASSPHRASE': os.environ.get('COINBASE_PASSPHRASE', ''),
'Content-Type': 'application/json',
'Accept': 'application/json'
}
return headers
def _generate_timestamp(self):
return str(int(time.time()))
def _generate_signature(self):
timestamp = self._generate_timestamp()
message = timestamp + 'GET' + '/users/self/balance'
mac = hmac.new(self.secret.encode('utf8'), message.encode('utf8'), hashlib.sha256)
signature = mac.hexdigest()
return signature
def get_balance(self):
endpoint = "{}/users/self/balance".format(self._get_endpoint())
response = self._send_request('GET', endpoint)
if response.status_code == requests.codes.ok:
return response.json()
<|file_sep|># coinbase
Coinbase Python client library.
## Installation
bash
$ pip install coinbase
## Usage
python
from coinbase.client import CoinbaseClient
client = CoinbaseClient(
key=os.environ.get('COINBASE_API_KEY'),
secret=os.environ.get('COINBASE_API_SECRET')
)
balance = client.get_balance()
print(balance)
<|file_sep|># coding=utf-8
"""
coinbase.py - Coinbase API client library.
"""
from __future__ import absolute_import
from .client import CoinbaseClient
__all__ = ['CoinbaseClient']
__title__ = 'coinbase'
__version__ = '0.1'
__author__ = 'Nico Guaro'
__license__ = 'MIT'
__copyright__ = 'Copyright (c) Nico Guaro'
<|repo_name|>zjybruce/NoteBook<|file_sep|>/LeetCode/leetcode_0017_letter_combinations_of_a_phone_number.md
# leetcode_0017_letter_combinations_of_a_phone_number
## 题目描述
给定一个仅包含数字2-9的字符串,返回所有它能表示的字母组合。
给出数字到字母的映射如下(与电话按键相同)。注意1不对应任何字母。

示例:
输入:"23"
输出:["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"].
说明:
尽管上面的答案是按字典序排列的,但是你可以任意选择答案输出的顺序。
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
## 解题思路
### 解法一:递归
思路:
1、定义一个字典,保存数字对应的字母列表。
2、定义一个函数`get_combination`,接收两个参数`index`和`temp_str`,分别表示当前遍历到的字符索引和当前已经组合好的字符串。该函数内部:
* 如果`index == len(digits)`,则说明已经完成组合,则将`temp_str`添加到结果列表中。
* 否则,获取当前字符对应的字母列表,并遍历该列表,调用本函数自身,并将`index+1`和`temp_str+当前字母`作为参数传入。
3、初始化结果列表,并调用函数`get_combination(0,"")`
python
class Solution:
def letterCombinations(self,digits:str)->List[str]:
# 定义一个字典,保存数字对应的字母列表。
digit_map={"2":"abc","3":"def","4":"ghi","5":"jkl","6":"mno","7":"pqrs","8":"tuv","9":"wxyz"}
res=[] # 初始化结果列表
def get_combination(index,temp_str):
if index==len(digits): # 如果已经完成组合,则将temp_str添加到结果列表中。
res.append(temp_str)
return
letters=digit_map[digits[index]] # 获取当前字符对应的字母列表,并遍历该列表,调用本函数自身,并将index+1和temp_str+当前字母作为参数传入。
for letter in letters:
get_combination(index+1,temp_str+letter)
if digits: # 如果digits不为空,则调用函数get_combination(0,"")
get_combination(0,"")
return res
### 解法二:迭代
思路:
1、定义一个字典,保存数字对应的字母列表。
2、初始化结果列表res,并将一个空字符串加入到res中。
3、遍历digits中的每个字符,根据当前字符在digit_map中查找其对应的字母列表。并使用双重循环实现字符串拼接。
python
class Solution:
def letterCombinations(self,digits:str)->List[str]:
# 定义一个字典,保存数字对应的字母列表。
digit_map={"2":"abc","3":"def","4":"ghi","5":"jkl","6":"mno","7":"pqrs","8":"tuv","9":"wxyz"}
res=[] # 初始化结果列表并将一个空字符串加入到res中。
res.append("")
for digit in digits: # 遍历digits中的每个字符,根据当前字符在digit_map中查找其对应的字母列表。并使用双重循环实现字符串拼接。
temp=[]
letters=digit_map[digit]
for i in range(len(res)):
s=res[i]
for j in range(len(letters)):
temp.append(s+letters[j])
res=temp
return res
<|repo_name|>zjybruce/NoteBook<|file_sep|>/LeetCode/leetcode_0085_maximal_rectangle.md
# leetcode_0085_maximal_rectangle
## 题目描述
给定一个仅包含0和1的二维二进制矩阵,找出只包含1的最大矩形,并返回其面积。

示例:
输入:
[
["1","0","1","0","0"],
["1","0","1","1","1"],
["1","1","1","1","1"],
["1","0","0","1","0"]
]
输出: 6
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/maximal-rectangle
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
## 解题思路
### 解法一:动态规划
思路:
如果某个位置为“1”,那么该位置所在行向上延伸的最大长度就是该位置上方连续“1”的个数加上它本身;如果某个位置为“0”,那么该位置所在行向上延伸的最大长度就是“0”。
然后使用动态规划求解最大矩形面积问题。
python
class Solution:
def maximalRectangle(self,matrix:List[List[str]])->int:
if not matrix or not matrix[0]:
return
m=len(matrix) # 行数
n=len(matrix[0]) # 列数
dp=[[0]*n for _ in range(m)] # 初始化dp数组
ans=0
for i in range(m): # dp[i][j]表示第i行第j列向上延伸的最大长度。
if matrix[i][0]=="1":
dp[i][0]=dp[i-1][0]+1 if i else 1
else:
dp[i][0]=0
ans=max(ans,dp[i][0]) # 计算当前行最大矩形面积。
for j in range(1,n):
if matrix[i][j]=="1":
dp[i][j]=dp[i-1][j]+1 if i else 1
else:
dp[i][j]=0
width=dp[i][j]
height=width
k=i
while k>=0 and dp[k][j]: # 使用动态规划求解最大矩形面积问题。
width=min(width,dp[k][j])
height+=width
ans=max(ans,height)
k-=1
return ans
<|repo_name|>zjybruce/NoteBook<|file_sep|>/LeetCode/leetcode_0138_copy_list_with_random_pointer.md
# leetcode_0138_copy_list_with_random_pointer
## 题目描述
给定一个链表,每个节点包含一个额外增加的随机指针,该指针可以指向链表中的任何节点或空节点。
要求返回这个链表的 深拷贝。
我们用一个