剑指Offer (汇总)

Posted on 2018-10-18 22:15  _hqc  阅读(302)  评论(0编辑  收藏  举报

刷完剑指Offer很久了,前几天想起来去年开通的博客园,正好把刷题笔记整理一下

刷题平台:牛客网

刷题语言:Python


**链表(8道)**


[剑指Offer 3. 从尾到头打印链表 (链表)](https://www.cnblogs.com/huangqiancun/p/9775456.html)
剑指Offer 14. 链表中倒数第k个结点 (链表): https://www.cnblogs.com/huangqiancun/p/9782576.html
剑指Offer 15. 反转链表 (链表): https://www.cnblogs.com/huangqiancun/p/9782581.html
剑指Offer 16. 合并两个排序的链表 (链表): https://www.cnblogs.com/huangqiancun/p/9784264.html
剑指Offer 25. 复杂链表的复制 (链表): https://www.cnblogs.com/huangqiancun/p/9789991.html
剑指Offer 36. 两个链表的第一个公共结点 (链表): https://www.cnblogs.com/huangqiancun/p/9797263.html
剑指Offer 55. 链表中环的入口结点 (链表): https://www.cnblogs.com/huangqiancun/p/9805173.html
剑指Offer 56. 删除链表中重复的结点 (链表): https://www.cnblogs.com/huangqiancun/p/9808851.html

二叉树(12道)
剑指Offer 4. 重建二叉树 (二叉树): https://www.cnblogs.com/huangqiancun/p/9775476.html
剑指Offer 17. 树的子结构 (二叉树): https://www.cnblogs.com/huangqiancun/p/9784299.html
剑指Offer 18. 二叉树的镜像 (二叉树): https://www.cnblogs.com/huangqiancun/p/9784305.html
剑指Offer 22. 从上往下打印二叉树 (二叉树): https://www.cnblogs.com/huangqiancun/p/9789961.html
剑指Offer 24. 二叉树中和为某一值的路径 (二叉树): https://www.cnblogs.com/huangqiancun/p/9789982.html
剑指Offer 38. 二叉树的深度 (二叉树): https://www.cnblogs.com/huangqiancun/p/9797276.html
剑指Offer 39. 平衡二叉树 (二叉树): https://www.cnblogs.com/huangqiancun/p/9797280.html
剑指Offer 57. 二叉树的下一个结点 (二叉树): https://www.cnblogs.com/huangqiancun/p/9808870.html
剑指Offer 58. 对称的二叉树 (二叉树): https://www.cnblogs.com/huangqiancun/p/9808886.html
剑指Offer 59. 按之字形顺序打印二叉树 (二叉树): https://www.cnblogs.com/huangqiancun/p/9808897.html
剑指Offer 60. 把二叉树打印成多行 (二叉树): https://www.cnblogs.com/huangqiancun/p/9808909.html
剑指Offer 61. 序列化二叉树 (二叉树): https://www.cnblogs.com/huangqiancun/p/9809252.html

二叉搜索树(3道)
剑指Offer 23. 二叉搜索树的后序遍历序列 (二叉搜索树): https://www.cnblogs.com/huangqiancun/p/9789968.html
剑指Offer 26. 二叉搜索树与双向链表 (二叉搜索树): https://www.cnblogs.com/huangqiancun/p/9790050.html
剑指Offer 62. 二叉搜索树的第k个结点 (二叉搜索树): https://www.cnblogs.com/huangqiancun/p/9809275.html

数组(11道)
剑指Offer 1. 二维数组中的查找 (数组): https://www.cnblogs.com/huangqiancun/p/9775118.html
剑指Offer 6. 旋转数组的最小数字 (数组): https://www.cnblogs.com/huangqiancun/p/9777569.html
剑指Offer 13. 调整数组顺序使奇数位于偶数前面 (数组): https://www.cnblogs.com/huangqiancun/p/9782564.html
剑指Offer 28. 数组中出现次数超过一半的数字 (数组): https://www.cnblogs.com/huangqiancun/p/9790076.html
剑指Offer 30. 连续子数组的最大和 (数组): https://www.cnblogs.com/huangqiancun/p/9790672.html
剑指Offer 32. 把数组排成最小的数 (数组): https://www.cnblogs.com/huangqiancun/p/9796739.html
剑指Offer 35. 数组中的逆序对 (数组): https://www.cnblogs.com/huangqiancun/p/9796785.html
剑指Offer 37. 数字在排序数组中出现的次数 (数组): https://www.cnblogs.com/huangqiancun/p/9797271.html
剑指Offer 40. 数组中只出现一次的数字 (数组): https://www.cnblogs.com/huangqiancun/p/9797284.html
剑指Offer 50. 数组中重复的数字 (数组): https://www.cnblogs.com/huangqiancun/p/9805081.html
剑指Offer 51. 构建乘积数组 (数组): https://www.cnblogs.com/huangqiancun/p/9805097.html

字符串(8道)
剑指Offer 2. 替换空格 (字符串): https://www.cnblogs.com/huangqiancun/p/9775425.html
剑指Offer 27. 字符串的排列 (字符串): https://www.cnblogs.com/huangqiancun/p/9790064.html
剑指Offer 34. 第一个只出现一次的字符 (字符串): https://www.cnblogs.com/huangqiancun/p/9796768.html
剑指Offer 43. 左旋转字符串 (字符串): https://www.cnblogs.com/huangqiancun/p/9797312.html
剑指Offer 44. 翻转单词顺序列 (字符串): https://www.cnblogs.com/huangqiancun/p/9797316.html
剑指Offer 49. 把字符串转换成整数 (字符串): https://www.cnblogs.com/huangqiancun/p/9805066.html
剑指Offer 52. 正则表达式匹配 (字符串): https://www.cnblogs.com/huangqiancun/p/9805124.html
剑指Offer 53. 表示数值的字符串 (字符串): https://www.cnblogs.com/huangqiancun/p/9805138.html

栈(3道)
剑指Offer 5. 用两个栈实现队列 (栈): https://www.cnblogs.com/huangqiancun/p/9775503.html
剑指Offer 20. 包含min函数的栈 (栈): https://www.cnblogs.com/huangqiancun/p/9784325.html
剑指Offer 21. 栈的压入、弹出序列 (栈): https://www.cnblogs.com/huangqiancun/p/9789942.html

递归(4道)
剑指Offer 7. 斐波那契数列 (递归): https://www.cnblogs.com/huangqiancun/p/9777581.html
剑指Offer 8. 跳台阶 (递归): https://www.cnblogs.com/huangqiancun/p/9777582.html
剑指Offer 9. 变态跳台阶 (递归): https://www.cnblogs.com/huangqiancun/p/9777588.html
剑指Offer 10. 矩形覆盖 (递归): https://www.cnblogs.com/huangqiancun/p/9777593.html

回溯(2道)
剑指Offer 65. 矩阵中的路径 (回溯): https://www.cnblogs.com/huangqiancun/p/9809322.html
剑指Offer 66. 机器人的运动范围 (回溯): https://www.cnblogs.com/huangqiancun/p/9809331.html

其他(15道)
剑指Offer 11. 二进制中1的个数 (其他): https://www.cnblogs.com/huangqiancun/p/9782553.html
剑指Offer 12. 数值的整数次方 (其他): https://www.cnblogs.com/huangqiancun/p/9782558.html
剑指Offer 19. 顺时针打印矩阵 (其他): https://www.cnblogs.com/huangqiancun/p/9784312.html
剑指Offer 29. 最小的K个数 (其他): https://www.cnblogs.com/huangqiancun/p/9790641.html
剑指Offer 31. 整数中1出现的次数(从1到n整数中1出现的次数) (其他): https://www.cnblogs.com/huangqiancun/p/9796710.html
剑指Offer 33. 丑数 (其他): https://www.cnblogs.com/huangqiancun/p/9796754.html
剑指Offer 41. 和为S的连续正数序列 (其他): https://www.cnblogs.com/huangqiancun/p/9797300.html
剑指Offer 42. 和为S的两个数字 (其他): https://www.cnblogs.com/huangqiancun/p/9797304.html
剑指Offer 45. 扑克牌顺子 (其他): https://www.cnblogs.com/huangqiancun/p/9797321.html
剑指Offer 46. 孩子们的游戏(圆圈中最后剩下的数) (其他): https://www.cnblogs.com/huangqiancun/p/9805026.html
剑指Offer 47. 求1+2+3+...+n (其他): https://www.cnblogs.com/huangqiancun/p/9805043.html
剑指Offer 48. 不用加减乘除做加法 (其他): https://www.cnblogs.com/huangqiancun/p/9805050.html
剑指Offer 54. 字符流中第一个不重复的字符 (其他): https://www.cnblogs.com/huangqiancun/p/9805155.html
剑指Offer 63. 数据流中的中位数(其他): https://www.cnblogs.com/huangqiancun/p/9809289.html
剑指Offer 64. 滑动窗口的最大值 (其他): https://www.cnblogs.com/huangqiancun/p/9809300.html

 

# -*- coding:utf-8 -*-
import requests
from bs4 import BeautifulSoup
if __name__ == '__main__':
    result = []
    for i in range(1,5)[::-1]:
        target = 'https://www.cnblogs.com/huangqiancun/tag/%E5%89%91%E6%8C%87Offer/default.html?page='+str(i)
        req = requests.get(url=target)
        html = req.text
        bf = BeautifulSoup(html,'html.parser')
        for j in range(20)[::-1]:
            index = "PostsList1_rpPosts_TitleUrl_"+str(j)
            texts = bf.find_all('a', id=index)
            if texts:
                name = texts[0].string
                address = texts[0].get('href')
                result.append(name + ''+ address)
    res = []
    res.extend([[' '],['链表(8道)']])
    for i in range(len(result)):
        if '(链表)' in result[i]:
            res.append(result[i])
    res.extend([[' '],['二叉树(12道)']])
    for i in range(len(result)):
        if '(二叉树)' in result[i]:
            res.append(result[i])
    res.extend([[' '],['二叉搜索树(3道)']])
    for i in range(len(result)):
        if '(二叉搜索树)' in result[i]:
            res.append(result[i])
    res.extend([[' '],['数组(11道)']])
    for i in range(len(result)):
        if '(数组)' in result[i]:
            res.append(result[i])
    res.extend([[' '],['字符串(8道)']])
    for i in range(len(result)):
        if '(字符串)' in result[i]:
            res.append(result[i])
    res.extend([[' '],['栈(3道)']])
    for i in range(len(result)):
        if '(栈)' in result[i]:
            res.append(result[i])
    res.extend([[' '],['递归(4道)']])
    for i in range(len(result)):
        if '(递归)' in result[i]:
            res.append(result[i])
    res.extend([[' '],['回溯(2道)']])
    for i in range(len(result)):
        if '(回溯)' in result[i]:
            res.append(result[i])
    res.extend([[' '],['其他(15道)']])
    for i in range(len(result)):
        if '(其他)' in result[i]:
            res.append(result[i])
    with open('剑指Offer.txt', 'a', encoding='utf-8') as f:
        for i in range(len(res)):
            f.writelines(res[i])
            f.write('\n')
    f.close()