【leetcode】解题日记(未完待续)

开坑,有生之年系列,希望有一天能解出 l e e t c o d e leetcode 上的所有题目。
写题解好麻烦,懒得写(手动狗头),进度如下。

总题数 已解答 题解数
1581 55 15

{ 0 50 100 150 简单: 9 + 一般: 5 + 困难: 1 + \def{\cGreen}{#52C41A}\def{\cOrange}{#F39C11}\def{\cYellow}{#FADB14}\def{\cRed}{#E74C3C}\def{\colorOfLine}{#A9A9A9}\def{\colorOfDivide}{#000000}\def{\colorOfName}{#000000}\def{\colorOfBox}{#000000}\def{\colorOfContent}{#000000}\newcommand{\item}[2]{ \color{\colorOfName} \textbf{#1:} \text{#2} &}\newcommand{\add}[2]{ \fcolorbox{\colorOfBox}{#2} {\normalsize\vphantom{+}\kern{#1 mm}}}\newcommand{\main}[3]{ \boxed{ \color{white} \begin{cases} &\color{\colorOfLine} \kern{4pt} \begin{vmatrix} \raisebox{60pt}{} \kern{48.56mm} \end{vmatrix} \kern{-5.5pt} \begin{vmatrix} \raisebox{60pt}{} \kern{48.56mm} \end{vmatrix} \kern{-5.5pt} \begin{vmatrix} \raisebox{60pt}{} \kern{48.56mm} \end{vmatrix} \\[-75pt] &\color{\colorOfDivide} \scriptsize \kern{4 pt} \text{0} \kern{48.2mm} \text{50} \kern{47 mm} \text{100} \kern{46 mm} \text{150} \\[3pt] \item{简单}{#1} \add{#1}{\cGreen} \\[3pt] \item{一般}{#2} \add{#2}{\cOrange} \\[3pt] \item{困难}{#3} \add{#3}{\cRed} \end{cases} } \\}\main{9}{5}{1}

【leetcode】6. Z 字形变换(zigzag-conversion)(字符串)[中等]
【leetcode】8. 字符串转换整数(atoi)(模拟)[中等]
【leetcode】9. 回文数(palindrome-number)(字符串)[简单]
【leetcode】10. 正则表达式匹配(regular-expression-matching)(DP)[困难]
【leetcode】13. 罗马数字转整数(roman-to-integer)(模拟)[简单]
【leetcode】14. 最长公共前缀(longest-common-prefix)(字符串)[简单]
【leetcode】26. 删除排序数组中的重复项(remove-duplicates-from-sorted-array)(双指针)[简单]
【leetcode】114. 二叉树展开为链表(Flatten Binary Tree to Linked List)(DFS)[中等]
【leetcode】136. 只出现一次的数字(Single Number)(位运算)[简单]
【leetcode】365. 水壶问题(water-and-jug-problem)(数学)[中等]
【leetcode】409. 最长回文串(longest-palindrome)(字符串)[简单]
【leetcode】836. 矩形重叠(rectangle-overlap)(计算几何)[简单]
【leetcode】876. 链表的中间结点(middle-of-the-linked-list)(链表)[简单]
【leetcode】945. 使数组唯一的最小增量(minimum-increment-to-make-array-unique)(贪心)[中等]
【leetcode】1160. 拼写单词(find-words-that-can-be-formed-by-characters)(字符串)[简单]

更新脚本

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time    : 2020/3/19-20 TAKE 5h 
# @Author  : Krone
# @Blog    : https://blog.csdn.net/Krone_/article/details/103437096
# @File    : leet.py
# @Software: Sublime

import re
import requests
import numpy as np
from lxml import html
from collections import namedtuple
from operator import attrgetter
import json
import pyperclip

# spider title and link 
url='https://blog.csdn.net/krone_/category_9430398.html' #需要爬数据的网址
page=requests.Session().get(url) 
tree=html.fromstring(page.text) 
link=tree.xpath('//*[@id="column"]/ul/li/a/@href') 
title=tree.xpath('//*[@id="column"]/ul/li/a/div[1]/h2[@class="title"]/text()') 
# str.strip() 去除字符串两边空格
title = [x.strip() for x in title]
title = [x for x in title if x != ""]

# all parts
start = "**开坑,有生之年系列,希望有一天能解出 $leetcode$ 上的所有题目。**\n**写题解好麻烦,懒得写(手动狗头),进度如下。**\n"

table = "| 总题数 |  已解答 | 题解数 |\n|--------|----------|--------|--------|\n"

Hard = len(list(filter(lambda x: re.search('困难', x) != None, title)))
Medium = len(list(filter(lambda x: re.search('中等', x) != None, title)))
Easy = len(list(filter(lambda x: re.search('简单', x) != None, title)))

report_problems = Hard+Medium+Easy

solve_problems = report_problems+40

# spider total_problems
url='https://leetcode-cn.com/api/problems/all/'
resp=requests.Session().get(url) 
question_list = json.loads(resp.content.decode('utf-8'))
total_problems = question_list['num_total']


pattern = re.compile(r'\d+')   # 查找数字
number = [pattern.findall(x) for x in title]

histogram = r"$\def{\cGreen}{#52C41A}\def{\cOrange}{#F39C11}\def{\cYellow}{#FADB14}\def{\cRed}{#E74C3C}\def{\colorOfLine}{#A9A9A9}\def{\colorOfDivide}{#000000}\def{\colorOfName}{#000000}\def{\colorOfBox}{#000000}\def{\colorOfContent}{#000000}\newcommand{\item}[2]{  \color{\colorOfName}  \textbf{#1:}  \text{#2} &}\newcommand{\add}[2]{    \fcolorbox{\colorOfBox}{#2}    {\normalsize\vphantom{+}\kern{#1 mm}}}\newcommand{\main}[3]{  \boxed{    \color{white}    \begin{cases} &\color{\colorOfLine}        \kern{4pt}        \begin{vmatrix}          \raisebox{60pt}{}          \kern{48.56mm}        \end{vmatrix}        \kern{-5.5pt}        \begin{vmatrix}          \raisebox{60pt}{}          \kern{48.56mm}        \end{vmatrix}        \kern{-5.5pt}        \begin{vmatrix}          \raisebox{60pt}{}          \kern{48.56mm}        \end{vmatrix} \\[-75pt]        &\color{\colorOfDivide}        \scriptsize        \kern{4 pt}        \text{0}        \kern{48.2mm}        \text{50}        \kern{47 mm}        \text{100}        \kern{46 mm}        \text{150} \\[3pt]        \item{简单}{#1} \add{#1}{\cGreen} \\[3pt]        \item{一般}{#2} \add{#2}{\cOrange} \\[3pt]        \item{困难}{#3} \add{#3}{\cRed}      \end{cases}    } \\}\main"

solveProLink = namedtuple('solveProLink', ['number', 'title', 'link'])

solveProLinkList = [solveProLink(int(number[i][0]), title[i], link[i]) for i in range(len(number)) if number[i]]

solveProLinkList = sorted(solveProLinkList, key=attrgetter('number'))

ans = 	start+"\n"+ \
		table + \
		"| "+str(total_problems)+" | "+str(solve_problems)+" | "+str(report_problems)+" |\n\n" + \
		histogram+"{{{0}}}{{{1}}}{{{2}}}$\n\n".format(Easy,Medium,Hard)

for item in solveProLinkList:
	ans += "["+item.title+"]"+"("+item.link+")\n"

ans += "\n**更新脚本**\n```py\n"

f0 = open(__file__, "r", encoding='UTF-8')
ans += f0.read()

ans += "\n```"

# Copy to clipboard
pyperclip.copy(ans) 


# # write content
# f = open('leetRepo.md','w')
# f.write(ans)
# f.close()
发布了76 篇原创文章 · 获赞 20 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/Krone_/article/details/103437096