From bbb1b27bb0edbea12fe653ec20b9579e68e83630 Mon Sep 17 00:00:00 2001 From: "yearing1017@126.com" Date: Tue, 7 Feb 2023 22:31:59 +0800 Subject: [PATCH 1/5] 2023-0-07 --- README.md | 144 +++++++++--------- leetcode/Hot-100/c++/lsxj.cpp | 38 +++++ .../Sort_Algorithm/BubbleSort.h" | 0 .../Sort_Algorithm/BubbleSort.py" | 0 .../Sort_Algorithm/BucketSort.cpp" | 0 .../Sort_Algorithm/HeapSort.cpp" | 0 .../Sort_Algorithm/InsertSort.h" | 0 .../Sort_Algorithm/MergeSort.h" | 0 .../Sort_Algorithm/QuickSort.h" | 0 .../Sort_Algorithm/RadixSort.h" | 0 .../Sort_Algorithm/SelectionSort.h" | 0 .../Sort_Algorithm/ShellSort.h" | 0 .../Sort_Algorithm/maxHeapSort.py" | 0 .../Sort_Algorithm/minHeapSort.py" | 0 .../Sort_Algorithm/quick_sort.py" | 0 .../BinaryTree.cpp" | 0 .../HashTable.cpp" | 0 .../LinkList.cpp" | 0 .../LinkList_with_head.cpp" | 0 .../RedBlackTree.cpp" | 0 .../SqList.cpp" | 0 .../SqStack.cpp" | 0 .../test_method.py" | 0 23 files changed, 110 insertions(+), 72 deletions(-) create mode 100644 leetcode/Hot-100/c++/lsxj.cpp rename Sort_Algorithm/BubbleSort.h => "\345\205\253\345\244\247\346\216\222\345\272\217\347\256\227\346\263\225/Sort_Algorithm/BubbleSort.h" (100%) rename Sort_Algorithm/BubbleSort.py => "\345\205\253\345\244\247\346\216\222\345\272\217\347\256\227\346\263\225/Sort_Algorithm/BubbleSort.py" (100%) rename Sort_Algorithm/BucketSort.cpp => "\345\205\253\345\244\247\346\216\222\345\272\217\347\256\227\346\263\225/Sort_Algorithm/BucketSort.cpp" (100%) rename Sort_Algorithm/HeapSort.cpp => "\345\205\253\345\244\247\346\216\222\345\272\217\347\256\227\346\263\225/Sort_Algorithm/HeapSort.cpp" (100%) rename Sort_Algorithm/InsertSort.h => "\345\205\253\345\244\247\346\216\222\345\272\217\347\256\227\346\263\225/Sort_Algorithm/InsertSort.h" (100%) rename Sort_Algorithm/MergeSort.h => "\345\205\253\345\244\247\346\216\222\345\272\217\347\256\227\346\263\225/Sort_Algorithm/MergeSort.h" (100%) rename Sort_Algorithm/QuickSort.h => "\345\205\253\345\244\247\346\216\222\345\272\217\347\256\227\346\263\225/Sort_Algorithm/QuickSort.h" (100%) rename Sort_Algorithm/RadixSort.h => "\345\205\253\345\244\247\346\216\222\345\272\217\347\256\227\346\263\225/Sort_Algorithm/RadixSort.h" (100%) rename Sort_Algorithm/SelectionSort.h => "\345\205\253\345\244\247\346\216\222\345\272\217\347\256\227\346\263\225/Sort_Algorithm/SelectionSort.h" (100%) rename Sort_Algorithm/ShellSort.h => "\345\205\253\345\244\247\346\216\222\345\272\217\347\256\227\346\263\225/Sort_Algorithm/ShellSort.h" (100%) rename Sort_Algorithm/maxHeapSort.py => "\345\205\253\345\244\247\346\216\222\345\272\217\347\256\227\346\263\225/Sort_Algorithm/maxHeapSort.py" (100%) rename Sort_Algorithm/minHeapSort.py => "\345\205\253\345\244\247\346\216\222\345\272\217\347\256\227\346\263\225/Sort_Algorithm/minHeapSort.py" (100%) rename Sort_Algorithm/quick_sort.py => "\345\205\253\345\244\247\346\216\222\345\272\217\347\256\227\346\263\225/Sort_Algorithm/quick_sort.py" (100%) rename DataStructure/BinaryTree.cpp => "\346\225\260\346\215\256\347\273\223\346\236\204/BinaryTree.cpp" (100%) rename DataStructure/HashTable.cpp => "\346\225\260\346\215\256\347\273\223\346\236\204/HashTable.cpp" (100%) rename DataStructure/LinkList.cpp => "\346\225\260\346\215\256\347\273\223\346\236\204/LinkList.cpp" (100%) rename DataStructure/LinkList_with_head.cpp => "\346\225\260\346\215\256\347\273\223\346\236\204/LinkList_with_head.cpp" (100%) rename DataStructure/RedBlackTree.cpp => "\346\225\260\346\215\256\347\273\223\346\236\204/RedBlackTree.cpp" (100%) rename DataStructure/SqList.cpp => "\346\225\260\346\215\256\347\273\223\346\236\204/SqList.cpp" (100%) rename DataStructure/SqStack.cpp => "\346\225\260\346\215\256\347\273\223\346\236\204/SqStack.cpp" (100%) rename DataStructure/test_method.py => "\346\225\260\346\215\256\347\273\223\346\236\204/test_method.py" (100%) diff --git a/README.md b/README.md index aad4dd1..307f9e6 100644 --- a/README.md +++ b/README.md @@ -329,90 +329,90 @@ ### Hot-100 | id | 题目 | 语言 | 题解链接 | | :--: | :------------------------: | :--: | :----------------------------------------------------------: | -| 2 | 两数相加 | Python | [2.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/lsxj.py) | -| 3 | 无重复字符的最长子串 | Python | [3.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/wcfzczc.py) | -| 5 | 最长回文子串 | Python | [5.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/zchwzc.py) | -| 12 | 整数转罗马数字 | Python | [12.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/zszlm.py) | -| 17 | 电话号码的字母组合 | Python | [17.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/dhhmzmzh.py) | -| 19 | 删除链表的倒数第n个结点 | Python | [19.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/lbdsdnd.py) | -| 21 | 合并两个有序链表 | Python | [21.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/hblgyxlb.py) | -| 22 | 括号生成 | Python | [22.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/khsc.py) | -| 23 | 合并K个升序链表 | Python | [23.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/hbkgsxlb.py) | -| 31 | 下一个排列* | Python | [31.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/xygpl.py) | -| 32 | 最长有效括号 | Python | [32.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/zcyxkh.py) | -| 33 | 搜索旋转排序数组 | Python | [33.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/ssxzpxsz.py) | -| 34 | 在排序数组中查找元素的第一个和最后一个位置 | Python | [34.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/leetcode/Hot-100/leftandright.py) | -| 39 | 组合总和 | Python | [39.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/zhzh.py) | -| 40 | 组合总和II | Python | [40.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/zhzh2.py) | -| 46 | 全排列 | Python | [46.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/qpl.py) | -| 48 | 旋转图像 | Python | [48.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/xztx.py) | -| 49 | 字母异位词 | Python | [49.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/zmywc.py) | -| 53 | 最大子序和 | Python | [53.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/zdzxh.py) | -| 55 | 跳跃游戏 | Python | [55.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/tyyx.py) | -| 56 | 合并区间 | Python | [56.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/hbqj.py) | -| 62 | 不同路径 | Python | [62.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/btlj.py) | -| 64 | 最小路径和 | Python | [64.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/zxljh.py) | -| 70 | 爬楼梯 | Python | [70.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/plt.py) | -| 75 | 颜色分类 | Python | [75.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/ysfl.py) | -| 78 | 子集 | Python | [78.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/zj.py) | -| 79 | 单词搜索 | Python | [79.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/dcss.py) | -| 81 | 搜索旋转排序数组2 | Python | [81.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/ssxzpxsz2.py) | -| 94 | 树的中序遍历 | Python | [94.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/zxbl.py) | -| 96 | 不同的二叉搜索树 | Python | [96.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/btdecsss.py) | -| 98 | 验证二叉搜索树 | Python | [98.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/yzecsss.py) | -| 101 | 对称二叉树 | Python | [101.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/dcecs.py) | -| 102 | 二叉树的层次遍历 | Python | [102.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/ecsdccbl.py) | -| 104 | 二叉树的最大深度 | Python | [104.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/ecsdzdsd.py) | +| 2 | 两数相加 | Python | [2.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/python/lsxj.py) | +| 3 | 无重复字符的最长子串 | Python | [3.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/python/wcfzczc.py) | +| 5 | 最长回文子串 | Python | [5.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/python/zchwzc.py) | +| 12 | 整数转罗马数字 | Python | [12.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/python/zszlm.py) | +| 17 | 电话号码的字母组合 | Python | [17.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/python/dhhmzmzh.py) | +| 19 | 删除链表的倒数第n个结点 | Python | [19.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/python/lbdsdnd.py) | +| 21 | 合并两个有序链表 | Python | [21.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/python/hblgyxlb.py) | +| 22 | 括号生成 | Python | [22.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/python/khsc.py) | +| 23 | 合并K个升序链表 | Python | [23.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/python/hbkgsxlb.py) | +| 31 | 下一个排列* | Python | [31.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/python/xygpl.py) | +| 32 | 最长有效括号 | Python | [32.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/python/zcyxkh.py) | +| 33 | 搜索旋转排序数组 | Python | [33.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/python/ssxzpxsz.py) | +| 34 | 在排序数组中查找元素的第一个和最后一个位置 | Python | [34.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/leetcode/Hot-100/python/leftandright.py) | +| 39 | 组合总和 | Python | [39.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/python/zhzh.py) | +| 40 | 组合总和II | Python | [40.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/python/zhzh2.py) | +| 46 | 全排列 | Python | [46.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/python/qpl.py) | +| 48 | 旋转图像 | Python | [48.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/python/xztx.py) | +| 49 | 字母异位词 | Python | [49.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/python/zmywc.py) | +| 53 | 最大子序和 | Python | [53.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/python/zdzxh.py) | +| 55 | 跳跃游戏 | Python | [55.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/python/tyyx.py) | +| 56 | 合并区间 | Python | [56.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/python/hbqj.py) | +| 62 | 不同路径 | Python | [62.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/python/btlj.py) | +| 64 | 最小路径和 | Python | [64.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/python/zxljh.py) | +| 70 | 爬楼梯 | Python | [70.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/python/plt.py) | +| 75 | 颜色分类 | Python | [75.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/python/ysfl.py) | +| 78 | 子集 | Python | [78.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/python/zj.py) | +| 79 | 单词搜索 | Python | [79.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/python/dcss.py) | +| 81 | 搜索旋转排序数组2 | Python | [81.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/python/ssxzpxsz2.py) | +| 94 | 树的中序遍历 | Python | [94.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/python/zxbl.py) | +| 96 | 不同的二叉搜索树 | Python | [96.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/python/btdecsss.py) | +| 98 | 验证二叉搜索树 | Python | [98.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/python/yzecsss.py) | +| 101 | 对称二叉树 | Python | [101.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/python/dcecs.py) | +| 102 | 二叉树的层次遍历 | Python | [102.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/python/ecsdccbl.py) | +| 104 | 二叉树的最大深度 | Python | [104.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/python/ecsdzdsd.py) | | 105 | 从前序和中序遍历序列构建二叉树 | Python | [105.py](/https://github.com/yearing1017/Algorithm_Note/blob/master/程序员代码面试指南-左程云/二叉树问题/rebuild_tree.py) | -| 108 | 将有序数组转换为二叉搜索树 | Python | [108.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/arr2bst.py) | -| 114 | 二叉树展开为链表* | Python | [114.py](/https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/tree2list.py) | +| 108 | 将有序数组转换为二叉搜索树 | Python | [108.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/python/arr2bst.py) | +| 114 | 二叉树展开为链表* | Python | [114.py](/https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/python/tree2list.py) | | 121 | 买卖股票的最佳时机 | Python | [121.py](/https://github.com/yearing1017/Algorithm_Note/blob/master/程序员代码面试指南-左程云/其他题目/gupiao1.py) | | 128 | 最长连续序列 | Python | [128.py](/https://github.com/yearing1017/Algorithm_Note/blob/master/程序员代码面试指南-左程云/其他题目/zclxxl.py) | -| 136 | 只出现一次的数字 | Python | [136.py](/https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/cxycdsz.py) | -| 139 | 单词拆分 | Python | [139.py](/https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/dccf.py) | +| 136 | 只出现一次的数字 | Python | [136.py](/https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/python/cxycdsz.py) | +| 139 | 单词拆分 | Python | [139.py](/https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/python/dccf.py) | | 141 | 环形链表 | Python | [141.py](https://github.com/yearing1017/Algorithm_Note/blob/master/程序员代码面试指南-左程云/链表问题/detectCycle_1.py) | | 142 | 环形链表的环形入口结点 | Python | [142.py](https://github.com/yearing1017/Algorithm_Note/blob/master/程序员代码面试指南-左程云/链表问题/detectCycle_2.py) | -| 148 | 排序链表 | Python | [148.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/pxlb.py) | -| 152 | 乘积最大子数组 | Python | [152.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/cjzdzsz.py) | +| 148 | 排序链表 | Python | [148.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/python/pxlb.py) | +| 152 | 乘积最大子数组 | Python | [152.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/python/cjzdzsz.py) | | 155 | 最小栈 | Python | [155.py](https://github.com/yearing1017/Algorithm_Note/blob/master/程序员代码面试指南-左程云/栈和队列/q1_1.py) | | 160 | 相交链表 | Python | [160.py](https://github.com/yearing1017/Algorithm_Note/blob/master/程序员代码面试指南-左程云/链表问题/detectCycle_3.py) | -| 169 | 多数元素 | Python | [169.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/dsys.py) | -| 198 | 打家劫舍 | Python | [198.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/djjs.py) | -| 200 | 岛屿数量 | Python | [200.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/dysl.py) | +| 169 | 多数元素 | Python | [169.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/python/dsys.py) | +| 198 | 打家劫舍 | Python | [198.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/python/djjs.py) | +| 200 | 岛屿数量 | Python | [200.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/python/dysl.py) | | 206 | 反转链表 | Python | [206.py](https://github.com/yearing1017/Algorithm_Note/blob/master/程序员代码面试指南-左程云/链表问题/q4.py) | -| 207 | 课程表 | Python | [207.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/kcb.py) | -| 208 | 前缀树 | Python | [208.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/qzs.py) | -| 213 | 打家劫舍2 | Python | [213.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/djjs2.py) | -| 215 | 数组中的第K个最大元素 | Python | [215.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/dkdys.py) | -| 221 | 最大正方形 | Python | [221.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/zdzfx.py) | -| 226 | 翻转二叉树 | Python | [226.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/fzecs.py) | -| 234 | 回文链表 | Python | [234.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/hwlb.py) | +| 207 | 课程表 | Python | [207.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/python/kcb.py) | +| 208 | 前缀树 | Python | [208.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/python/qzs.py) | +| 213 | 打家劫舍2 | Python | [213.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/python/djjs2.py) | +| 215 | 数组中的第K个最大元素 | Python | [215.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/python/dkdys.py) | +| 221 | 最大正方形 | Python | [221.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/python/zdzfx.py) | +| 226 | 翻转二叉树 | Python | [226.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/python/fzecs.py) | +| 234 | 回文链表 | Python | [234.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/python/hwlb.py) | | 236 | 二叉树最近公共祖先节点 | Python | [236.py](https://github.com/yearing1017/Algorithm_Note/blob/master/程序员代码面试指南-左程云/二叉树问题/q18.py) | -| 238 | 除自身以外数组的乘积* | Python | [338.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/czsywdcj.py) | +| 238 | 除自身以外数组的乘积* | Python | [338.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/python/czsywdcj.py) | | 240 | 搜索二维矩阵2 | Python | [240.py](https://github.com/yearing1017/Algorithm_Note/blob/master/程序员代码面试指南-左程云/数组和矩阵问题/q7.py) | -| 279 | 完全平方数 | Python | [279.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/wqpfs.py) | -| 283 | 移动零 | Python | [283.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/ydl.py) | -| 297 | 二叉树的序列化与反序列化 | Python | [297.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/xlhyfxlh.py) | -| 300 | 最长递增子序列 | Python | [300.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/zcdzzxl.py) | +| 279 | 完全平方数 | Python | [279.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/python/wqpfs.py) | +| 283 | 移动零 | Python | [283.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/python/ydl.py) | +| 297 | 二叉树的序列化与反序列化 | Python | [297.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/python/xlhyfxlh.py) | +| 300 | 最长递增子序列 | Python | [300.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/python/zcdzzxl.py) | | 309 | 股票(含冷冻期) | Python | [309.py](https://github.com/yearing1017/Algorithm_Note/blob/master/程序员代码面试指南-左程云/其他题目/gupiao5.py) | -| 332 | 零钱兑换 | Python | [332.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/lqdh.py) | +| 332 | 零钱兑换 | Python | [332.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/python/lqdh.py) | | 337 | 打家劫舍3 | Python | [337.py](https://github.com/yearing1017/Algorithm_Note/blob/master/程序员代码面试指南-左程云/其他题目/djjs3.py) | -| 338 | 比特位计数 | Python | [338.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/btwjs.py) | -| 394 | 字符串解码 | Python | [394.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/zfcjm.py) | -| 399 | 除法求值 | Python | [399.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/cfqz.py) | -| 406 | 根据身高重建队列 | Python | [406.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/gjsgcjdl.py) | -| 416 | 分割等和子集 | Python | [416.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/fgdhzj.py) | -| 437 | 路径总和3 | Python | [437.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/ljzh3.py) | -| 438 | 找到字符串中的所有字母异位词 | Python | [438.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/zmywc2.py) | -| 448 | 找到所有数组中消失的数字 | Python | [448.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/xsdsz.py) | -| 461 | 汉明距离 | Python | [461.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/hmjl.py) | -| 538 | 把二叉搜索树转为累加树 | Python | [538.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/ljs.py) | -| 543 | 二叉树的直径 | Python | [543.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/ecszj.py) | -| 560 | 和为k的子数组 | Python | [560.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/kzsz.py) | -| 581 | 最短无序连续子数组 | Python | [543.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/zdwxlxzsz.py) | -| 617 | 合并二叉树 | Python | [617.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/hbecs.py) | -| 647 | 回文子串 | Python | [617.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/hwzc.py) | -| 739 | 每日温度 | Python | [739.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/mrwd.py) | +| 338 | 比特位计数 | Python | [338.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/python/btwjs.py) | +| 394 | 字符串解码 | Python | [394.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/python/zfcjm.py) | +| 399 | 除法求值 | Python | [399.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/python/cfqz.py) | +| 406 | 根据身高重建队列 | Python | [406.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/python/gjsgcjdl.py) | +| 416 | 分割等和子集 | Python | [416.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/python/fgdhzj.py) | +| 437 | 路径总和3 | Python | [437.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/python/ljzh3.py) | +| 438 | 找到字符串中的所有字母异位词 | Python | [438.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/python/zmywc2.py) | +| 448 | 找到所有数组中消失的数字 | Python | [448.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/python/xsdsz.py) | +| 461 | 汉明距离 | Python | [461.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/python/hmjl.py) | +| 538 | 把二叉搜索树转为累加树 | Python | [538.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/python/ljs.py) | +| 543 | 二叉树的直径 | Python | [543.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/python/ecszj.py) | +| 560 | 和为k的子数组 | Python | [560.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/python/kzsz.py) | +| 581 | 最短无序连续子数组 | Python | [543.py](https://github.com/yearing1017/Algorithm_Note/blob/master/leetcode/Hot-100/python/zdwxlxzsz.py) | +| 617 | 合并二叉树 | Python | [617.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/python/hbecs.py) | +| 647 | 回文子串 | Python | [617.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/python/hwzc.py) | +| 739 | 每日温度 | Python | [739.py](/Users/yearing1017/GitHub_repo/Algorithm_Note/blob/master/leetcode/Hot-100/python/mrwd.py) | ### 随机刷题目 diff --git a/leetcode/Hot-100/c++/lsxj.cpp b/leetcode/Hot-100/c++/lsxj.cpp new file mode 100644 index 0000000..0ce0242 --- /dev/null +++ b/leetcode/Hot-100/c++/lsxj.cpp @@ -0,0 +1,38 @@ +/** + * Definition for singly-linked list. + * struct ListNode { + * int val; + * ListNode *next; + * ListNode() : val(0), next(nullptr) {} + * ListNode(int x) : val(x), next(nullptr) {} + * ListNode(int x, ListNode *next) : val(x), next(next) {} + * }; + */ +class Solution { +public: + ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) { + int ca = 0, n1 = 0, n2 = 0, n = 0; + ListNode *dummy = new ListNode(-1), *pre = dummy, *node = nullptr; + ListNode *cur1 = l1, *cur2 = l2; + + while (cur1 || cur2) { + n1 = cur1 ? cur1->val: 0; + n2 = cur2 ? cur2->val: 0; + n = n1 + n2 + ca; + node = new ListNode(n % 10); + pre->next = node; + pre = node; + ca = n / 10; + cur1 = cur1 ? cur1->next : nullptr; + cur2 = cur2 ? cur2->next : nullptr; + } + + if (ca == 1) { + node = new ListNode(1); + pre->next = node; + } + + return dummy->next; + + } +}; \ No newline at end of file diff --git a/Sort_Algorithm/BubbleSort.h "b/\345\205\253\345\244\247\346\216\222\345\272\217\347\256\227\346\263\225/Sort_Algorithm/BubbleSort.h" similarity index 100% rename from Sort_Algorithm/BubbleSort.h rename to "\345\205\253\345\244\247\346\216\222\345\272\217\347\256\227\346\263\225/Sort_Algorithm/BubbleSort.h" diff --git a/Sort_Algorithm/BubbleSort.py "b/\345\205\253\345\244\247\346\216\222\345\272\217\347\256\227\346\263\225/Sort_Algorithm/BubbleSort.py" similarity index 100% rename from Sort_Algorithm/BubbleSort.py rename to "\345\205\253\345\244\247\346\216\222\345\272\217\347\256\227\346\263\225/Sort_Algorithm/BubbleSort.py" diff --git a/Sort_Algorithm/BucketSort.cpp "b/\345\205\253\345\244\247\346\216\222\345\272\217\347\256\227\346\263\225/Sort_Algorithm/BucketSort.cpp" similarity index 100% rename from Sort_Algorithm/BucketSort.cpp rename to "\345\205\253\345\244\247\346\216\222\345\272\217\347\256\227\346\263\225/Sort_Algorithm/BucketSort.cpp" diff --git a/Sort_Algorithm/HeapSort.cpp "b/\345\205\253\345\244\247\346\216\222\345\272\217\347\256\227\346\263\225/Sort_Algorithm/HeapSort.cpp" similarity index 100% rename from Sort_Algorithm/HeapSort.cpp rename to "\345\205\253\345\244\247\346\216\222\345\272\217\347\256\227\346\263\225/Sort_Algorithm/HeapSort.cpp" diff --git a/Sort_Algorithm/InsertSort.h "b/\345\205\253\345\244\247\346\216\222\345\272\217\347\256\227\346\263\225/Sort_Algorithm/InsertSort.h" similarity index 100% rename from Sort_Algorithm/InsertSort.h rename to "\345\205\253\345\244\247\346\216\222\345\272\217\347\256\227\346\263\225/Sort_Algorithm/InsertSort.h" diff --git a/Sort_Algorithm/MergeSort.h "b/\345\205\253\345\244\247\346\216\222\345\272\217\347\256\227\346\263\225/Sort_Algorithm/MergeSort.h" similarity index 100% rename from Sort_Algorithm/MergeSort.h rename to "\345\205\253\345\244\247\346\216\222\345\272\217\347\256\227\346\263\225/Sort_Algorithm/MergeSort.h" diff --git a/Sort_Algorithm/QuickSort.h "b/\345\205\253\345\244\247\346\216\222\345\272\217\347\256\227\346\263\225/Sort_Algorithm/QuickSort.h" similarity index 100% rename from Sort_Algorithm/QuickSort.h rename to "\345\205\253\345\244\247\346\216\222\345\272\217\347\256\227\346\263\225/Sort_Algorithm/QuickSort.h" diff --git a/Sort_Algorithm/RadixSort.h "b/\345\205\253\345\244\247\346\216\222\345\272\217\347\256\227\346\263\225/Sort_Algorithm/RadixSort.h" similarity index 100% rename from Sort_Algorithm/RadixSort.h rename to "\345\205\253\345\244\247\346\216\222\345\272\217\347\256\227\346\263\225/Sort_Algorithm/RadixSort.h" diff --git a/Sort_Algorithm/SelectionSort.h "b/\345\205\253\345\244\247\346\216\222\345\272\217\347\256\227\346\263\225/Sort_Algorithm/SelectionSort.h" similarity index 100% rename from Sort_Algorithm/SelectionSort.h rename to "\345\205\253\345\244\247\346\216\222\345\272\217\347\256\227\346\263\225/Sort_Algorithm/SelectionSort.h" diff --git a/Sort_Algorithm/ShellSort.h "b/\345\205\253\345\244\247\346\216\222\345\272\217\347\256\227\346\263\225/Sort_Algorithm/ShellSort.h" similarity index 100% rename from Sort_Algorithm/ShellSort.h rename to "\345\205\253\345\244\247\346\216\222\345\272\217\347\256\227\346\263\225/Sort_Algorithm/ShellSort.h" diff --git a/Sort_Algorithm/maxHeapSort.py "b/\345\205\253\345\244\247\346\216\222\345\272\217\347\256\227\346\263\225/Sort_Algorithm/maxHeapSort.py" similarity index 100% rename from Sort_Algorithm/maxHeapSort.py rename to "\345\205\253\345\244\247\346\216\222\345\272\217\347\256\227\346\263\225/Sort_Algorithm/maxHeapSort.py" diff --git a/Sort_Algorithm/minHeapSort.py "b/\345\205\253\345\244\247\346\216\222\345\272\217\347\256\227\346\263\225/Sort_Algorithm/minHeapSort.py" similarity index 100% rename from Sort_Algorithm/minHeapSort.py rename to "\345\205\253\345\244\247\346\216\222\345\272\217\347\256\227\346\263\225/Sort_Algorithm/minHeapSort.py" diff --git a/Sort_Algorithm/quick_sort.py "b/\345\205\253\345\244\247\346\216\222\345\272\217\347\256\227\346\263\225/Sort_Algorithm/quick_sort.py" similarity index 100% rename from Sort_Algorithm/quick_sort.py rename to "\345\205\253\345\244\247\346\216\222\345\272\217\347\256\227\346\263\225/Sort_Algorithm/quick_sort.py" diff --git a/DataStructure/BinaryTree.cpp "b/\346\225\260\346\215\256\347\273\223\346\236\204/BinaryTree.cpp" similarity index 100% rename from DataStructure/BinaryTree.cpp rename to "\346\225\260\346\215\256\347\273\223\346\236\204/BinaryTree.cpp" diff --git a/DataStructure/HashTable.cpp "b/\346\225\260\346\215\256\347\273\223\346\236\204/HashTable.cpp" similarity index 100% rename from DataStructure/HashTable.cpp rename to "\346\225\260\346\215\256\347\273\223\346\236\204/HashTable.cpp" diff --git a/DataStructure/LinkList.cpp "b/\346\225\260\346\215\256\347\273\223\346\236\204/LinkList.cpp" similarity index 100% rename from DataStructure/LinkList.cpp rename to "\346\225\260\346\215\256\347\273\223\346\236\204/LinkList.cpp" diff --git a/DataStructure/LinkList_with_head.cpp "b/\346\225\260\346\215\256\347\273\223\346\236\204/LinkList_with_head.cpp" similarity index 100% rename from DataStructure/LinkList_with_head.cpp rename to "\346\225\260\346\215\256\347\273\223\346\236\204/LinkList_with_head.cpp" diff --git a/DataStructure/RedBlackTree.cpp "b/\346\225\260\346\215\256\347\273\223\346\236\204/RedBlackTree.cpp" similarity index 100% rename from DataStructure/RedBlackTree.cpp rename to "\346\225\260\346\215\256\347\273\223\346\236\204/RedBlackTree.cpp" diff --git a/DataStructure/SqList.cpp "b/\346\225\260\346\215\256\347\273\223\346\236\204/SqList.cpp" similarity index 100% rename from DataStructure/SqList.cpp rename to "\346\225\260\346\215\256\347\273\223\346\236\204/SqList.cpp" diff --git a/DataStructure/SqStack.cpp "b/\346\225\260\346\215\256\347\273\223\346\236\204/SqStack.cpp" similarity index 100% rename from DataStructure/SqStack.cpp rename to "\346\225\260\346\215\256\347\273\223\346\236\204/SqStack.cpp" diff --git a/DataStructure/test_method.py "b/\346\225\260\346\215\256\347\273\223\346\236\204/test_method.py" similarity index 100% rename from DataStructure/test_method.py rename to "\346\225\260\346\215\256\347\273\223\346\236\204/test_method.py" From eabe7e274ae04608df5bdca6ece27aee339a4c26 Mon Sep 17 00:00:00 2001 From: "yearing1017@126.com" Date: Wed, 8 Feb 2023 22:16:26 +0800 Subject: [PATCH 2/5] 20230208 --- leetcode/Hot-100/c++/wcfzfdzczc.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 leetcode/Hot-100/c++/wcfzfdzczc.cpp diff --git a/leetcode/Hot-100/c++/wcfzfdzczc.cpp b/leetcode/Hot-100/c++/wcfzfdzczc.cpp new file mode 100644 index 0000000..06cc3b0 --- /dev/null +++ b/leetcode/Hot-100/c++/wcfzfdzczc.cpp @@ -0,0 +1,19 @@ +class Solution { +public: + int lengthOfLongestSubstring(string s) { + if(s.size() == 0) return 0; + int pre = -1, length = 0, cur_len = 0; + unordered_map dic; + + for (int i = 0; i < s.size(); i++) { + if (dic.find(s[i]) != dic.end()) { + pre = max(pre, dic[s[i]]); + } + // 将s[i]的索引加到字典 或更新索引 + dic[s[i]] = i; + cur_len = i - pre; + length = max(length, cur_len); + } + return length; + } +}; \ No newline at end of file From 7ab13a603b1d7d7524c87748c4b4f79484f39d26 Mon Sep 17 00:00:00 2001 From: "yearing1017@126.com" Date: Tue, 5 Sep 2023 22:04:07 +0800 Subject: [PATCH 3/5] 20230905 --- leetcode/Hot-100/c++/czdsdrq.cpp | 20 +++++++++++++ leetcode/Hot-100/c++/sszh.cpp | 44 +++++++++++++++++++++++++++++ leetcode/Hot-100/c++/zchwzc.cpp | 45 ++++++++++++++++++++++++++++++ leetcode/Hot-100/python/czdsdrq.py | 16 +++++++++++ 4 files changed, 125 insertions(+) create mode 100644 leetcode/Hot-100/c++/czdsdrq.cpp create mode 100644 leetcode/Hot-100/c++/sszh.cpp create mode 100644 leetcode/Hot-100/c++/zchwzc.cpp create mode 100644 leetcode/Hot-100/python/czdsdrq.py diff --git a/leetcode/Hot-100/c++/czdsdrq.cpp b/leetcode/Hot-100/c++/czdsdrq.cpp new file mode 100644 index 0000000..f16da4b --- /dev/null +++ b/leetcode/Hot-100/c++/czdsdrq.cpp @@ -0,0 +1,20 @@ +class Solution { +public: + int maxArea(vector& height) { + int i = 0; + int j = height.size()-1; + + int res = 0; + + while (i < j) { + if (height[i] < height[j]) { + res = max(res, height[i] * (j-i)); + i++; + } else { + res = max(res, height[j] * (j-i)); + j--; + } + } + return res; + } +}; \ No newline at end of file diff --git a/leetcode/Hot-100/c++/sszh.cpp b/leetcode/Hot-100/c++/sszh.cpp new file mode 100644 index 0000000..0c1835f --- /dev/null +++ b/leetcode/Hot-100/c++/sszh.cpp @@ -0,0 +1,44 @@ +class Solution { +public: + vector> threeSum(vector& nums) { + vector> res; + int len = nums.size(); + if (len < 3) { + return res; + } + // 先排序 之后遍历遇到正数即可停止 + sort(nums.begin(), nums.end()); + for (int i = 0; i < len; i++) { + if (nums[i] > 0) { + break; + } + // 去重 + if (i > 0 && nums[i] == nums[i-1]) { + continue; + } + // 定住第一个数的同时 从右边开始两边向中间缩 + int left = i + 1; + int right = len - 1; + while (left < right) { + if (nums[i] + nums[left] + nums[right] == 0) { + res.push_back({nums[i], nums[left], nums[right]}); + // 去重 + while (left < right && nums[left] == nums[left+1]) { + left += 1; + } + while (left < right && nums[right] == nums[right-1]) { + right -= 1; + } + // 去重完还要移动一次 + left += 1; + right -= 1; + } else if (nums[i] + nums[left] + nums[right] < 0) { + left += 1; + } else { + right -= 1; + } + } + } + return res; + } +}; \ No newline at end of file diff --git a/leetcode/Hot-100/c++/zchwzc.cpp b/leetcode/Hot-100/c++/zchwzc.cpp new file mode 100644 index 0000000..0a9a717 --- /dev/null +++ b/leetcode/Hot-100/c++/zchwzc.cpp @@ -0,0 +1,45 @@ +class Solution { +public: + string longestPalindrome(string s) { + int n = s.size(); + + if(n < 2) { + return s; + } + + int start = 0; + int maxLen = 1; + int curLen = 0; + // dp[i][j] 表示以A[i]开头和A[j]结尾的字符串是否为回文串 + vector> dp(n, vector(n)); + + // 初始化:所有长度为 1 的子串都是回文串 + for(int i=0; i=0; i--) { + for (int j=i+1; j maxLen) { + maxLen = curLen; + // 最长回文子串的起始字母的下标 + start = i; + } + } + } + } + return s.substr(start, maxLen); + } +}; \ No newline at end of file diff --git a/leetcode/Hot-100/python/czdsdrq.py b/leetcode/Hot-100/python/czdsdrq.py new file mode 100644 index 0000000..07dd74f --- /dev/null +++ b/leetcode/Hot-100/python/czdsdrq.py @@ -0,0 +1,16 @@ +class Solution: + def maxArea(self, height: List[int]) -> int: + # O(N) O(1) + i = 0 + j = len(height) -1 + res = 0 + # 每次的面积大小都由短板决定 + while i < j: + # 每次向内收缩短板 面积才有可能扩大 收缩长板 短板大小可能不变可能减少 + if height[i] < height[j]: + res = max(res, height[i]*(j-i)) + i += 1 + else: + res = max(res, height[j]*(j-i)) + j -= 1 + return res \ No newline at end of file From fdfa11750d19d7f8db86fe6a26f9280b1221dc4a Mon Sep 17 00:00:00 2001 From: "yearing1017@126.com" Date: Wed, 6 Sep 2023 21:57:08 +0800 Subject: [PATCH 4/5] 20230906 --- leetcode/Hot-100/c++/dhhmdzmzh.cpp | 41 ++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 leetcode/Hot-100/c++/dhhmdzmzh.cpp diff --git a/leetcode/Hot-100/c++/dhhmdzmzh.cpp b/leetcode/Hot-100/c++/dhhmdzmzh.cpp new file mode 100644 index 0000000..681c287 --- /dev/null +++ b/leetcode/Hot-100/c++/dhhmdzmzh.cpp @@ -0,0 +1,41 @@ +class Solution { +public: + vector res; + unordered_map phoneMap{ + {'2', "abc"}, + {'3', "def"}, + {'4', "ghi"}, + {'5', "jkl"}, + {'6', "mno"}, + {'7', "pqrs"}, + {'8', "tuv"}, + {'9', "wxyz"} + }; + string temp; + + void DFS(int pos, string digits){ + if (pos == digits.size()){ + res.push_back(temp); + //return; + } else { + char digit = digits[pos]; + for (const char& letter: phoneMap[digit]) { + temp.push_back(letter); + DFS(pos+1, digits); + temp.pop_back(); + } + } + + } + vector letterCombinations(string digits) { + + if (digits.size() == 0) { + return res; + } + DFS(0, digits); + return res; + + } + + +}; \ No newline at end of file From e781258ecd0c6f6a34929fae465a0e3b3b194940 Mon Sep 17 00:00:00 2001 From: "yearing1017@126.com" Date: Wed, 11 Oct 2023 22:44:15 +0800 Subject: [PATCH 5/5] 20231011 --- leetcode/Hot-100/c++/khsc.cpp | 29 ++++++++++++ leetcode/Hot-100/c++/sclbddsdngjd.cpp | 39 ++++++++++++++++ leetcode/Hot-100/c++/ssxzpxsz.cpp | 33 ++++++++++++++ leetcode/Hot-100/c++/zpxszzczysdyzhwz.cpp | 47 ++++++++++++++++++++ leetcode/Hot-100/c++/zpxszzzd | 0 leetcode/Hot-100/python/lbdsdnd.py | 2 + leetcode/Hot-100/python/leftandright.py | 54 ++++++++++++++--------- 7 files changed, 183 insertions(+), 21 deletions(-) create mode 100644 leetcode/Hot-100/c++/khsc.cpp create mode 100644 leetcode/Hot-100/c++/sclbddsdngjd.cpp create mode 100644 leetcode/Hot-100/c++/ssxzpxsz.cpp create mode 100644 leetcode/Hot-100/c++/zpxszzczysdyzhwz.cpp create mode 100644 leetcode/Hot-100/c++/zpxszzzd diff --git a/leetcode/Hot-100/c++/khsc.cpp b/leetcode/Hot-100/c++/khsc.cpp new file mode 100644 index 0000000..acacc10 --- /dev/null +++ b/leetcode/Hot-100/c++/khsc.cpp @@ -0,0 +1,29 @@ +class Solution { +public: + vector generateParenthesis(int n) { + vector res; + string temp; + dfs(temp, n, n, res); + return res; + } + + void dfs(string& temp, int left, int right, vector& res) { + if (left == 0 && right == 0) { + res.push_back(temp); + return; + } + + if (right < left) { + return; + } + + if (left > 0) { + string cur_temp = temp + '('; + dfs(cur_temp, left-1, right, res); + } + if (right > 0) { + string cur_temp = temp + ')'; + dfs(cur_temp, left, right-1, res); + } + } +}; \ No newline at end of file diff --git a/leetcode/Hot-100/c++/sclbddsdngjd.cpp b/leetcode/Hot-100/c++/sclbddsdngjd.cpp new file mode 100644 index 0000000..878b5c4 --- /dev/null +++ b/leetcode/Hot-100/c++/sclbddsdngjd.cpp @@ -0,0 +1,39 @@ +/** + * Definition for singly-linked list. + * struct ListNode { + * int val; + * ListNode *next; + * ListNode() : val(0), next(nullptr) {} + * ListNode(int x) : val(x), next(nullptr) {} + * ListNode(int x, ListNode *next) : val(x), next(next) {} + * }; + */ +class Solution { +public: + + int getLength(ListNode* head) { + int len = 0; + while(head) { + ++len; + head = head->next; + } + return len; + } + ListNode* removeNthFromEnd(ListNode* head, int n) { + // 伪头结点 + ListNode* dummy = new ListNode(0, head); + int len = getLength(head); + ListNode* cur = dummy; + + // len-n+1;cur 1 2 3 4 5 6 倒数第2集正数第5;从dummy移动,找到前一个点 + for (int i = 1; i < len - n +1; i++) { + cur = cur->next; + } + + cur->next = cur->next->next; + ListNode* res = dummy->next; + delete dummy; + return res; + + } +}; \ No newline at end of file diff --git a/leetcode/Hot-100/c++/ssxzpxsz.cpp b/leetcode/Hot-100/c++/ssxzpxsz.cpp new file mode 100644 index 0000000..78d4172 --- /dev/null +++ b/leetcode/Hot-100/c++/ssxzpxsz.cpp @@ -0,0 +1,33 @@ +class Solution { +public: + int search(vector& nums, int target) { + int length = nums.size(); + int l = 0; + int r = length - 1; + int mid; + while (l <= r) { + mid = (l + r) / 2; + if (nums[mid] == target) { + return mid; + } + + // 左半区 + if (nums[mid] > nums[r]) { + // 左半区左 + if (target >= nums[l] and target <= nums[mid]) { + r = mid - 1; + } else { + l = mid + 1; + } + } else { + // 右半区右 + if (target >= nums[mid] and target <= nums[r]) { + l = mid + 1; + } else { + r = mid - 1; + } + } + } + return -1; + } +}; \ No newline at end of file diff --git a/leetcode/Hot-100/c++/zpxszzczysdyzhwz.cpp b/leetcode/Hot-100/c++/zpxszzczysdyzhwz.cpp new file mode 100644 index 0000000..d47d309 --- /dev/null +++ b/leetcode/Hot-100/c++/zpxszzczysdyzhwz.cpp @@ -0,0 +1,47 @@ +class Solution { +public: + vector searchRange(vector& nums, int target) { + if (nums.size() == 0) { + return vector{-1, -1}; + } + + int left = biLeft(nums, target); + int right = biRighft(nums, target); + + if (left<0 || left>=nums.size() || right<0 || right>=nums.size()){ + return vector{-1, -1}; + } else if (nums[left] != target || nums[right] != target) { + return vector{-1, -1}; + } else { + return vector{left, right}; + } + } + + int biLeft(vector& nums, int target) { + int i = 0; + int j = nums.size()-1; + while (i <= j) { + int m = (i+j) / 2; + if (nums[m] < target) { + i = m + 1; + } else { + j = m - 1; + } + } + return i; + } + + int biRighft(vector& nums, int target) { + int i = 0; + int j = nums.size()-1; + while (i <= j) { + int m = (i+j) / 2; + if (nums[m] <= target) { + i = m + 1; + } else { + j = m - 1; + } + } + return j; + } +}; \ No newline at end of file diff --git a/leetcode/Hot-100/c++/zpxszzzd b/leetcode/Hot-100/c++/zpxszzzd new file mode 100644 index 0000000..e69de29 diff --git a/leetcode/Hot-100/python/lbdsdnd.py b/leetcode/Hot-100/python/lbdsdnd.py index 1bb6fe3..456dca4 100644 --- a/leetcode/Hot-100/python/lbdsdnd.py +++ b/leetcode/Hot-100/python/lbdsdnd.py @@ -11,6 +11,8 @@ def __init__(self, val=0, next=None): self.next = next class Solution: def removeNthFromEnd(self, head: ListNode, n: int) -> ListNode: + # 先找规律 倒数第n个结点 = 正数第 len-n+1 个结点 + # 例如:1 2 3 4 5 6; 6 2 5; 6 3 4; 6 5 2 cur = head #pre = head del_node = head diff --git a/leetcode/Hot-100/python/leftandright.py b/leetcode/Hot-100/python/leftandright.py index 80412c2..308da47 100644 --- a/leetcode/Hot-100/python/leftandright.py +++ b/leetcode/Hot-100/python/leftandright.py @@ -7,28 +7,40 @@ """ from typing import List - class Solution: def searchRange(self, nums: List[int], target: int) -> List[int]: - left = self.binarySearch(nums, target, True) - right = self.binarySearch(nums, target, False) - 1 - # 找到之后检验一下是否符合条件 - if left <= right and right <= len(nums)-1 and nums[left] == target and nums[right] == target: - return [left, right] - else: + if not nums: + return [-1,-1] + left = self.bi_left(nums, target) + right = self.bi_right(nums, target) + + if not 0 <= left < len(nums) or not 0 <= right < len(nums): + return [-1, -1] + elif nums[left] != target or nums[right] != target: return [-1, -1] - # lower 为true代表找第一个位置 - def binarySearch(self, nums, target, lower): - l = 0 - r = len(nums) - 1 - # 只有一个数时 [1] 找到第一个大于1的下标为1 再 -1 - ans = len(nums) - while l <= r: - mid = (l+r) // 2 - # 找第一个target 即找到第一个>=target的位置 第二个 即找到 >target的位置 再 -1 - if (nums[mid] > target) or (lower and nums[mid] >= target): - r = mid - 1 - ans = mid + else: + return[left, right] + + def bi_left(self, nums, target): + # 5,7,7,8,8,10 8 + i = 0 + j = len(nums)-1 + while i <= j: + m = (i+j)//2 + if nums[m] < target: + i = m + 1 + else: + j = m - 1 + return i + + def bi_right(self, nums, target): + # 5,7,7,8,8,10 8 + i = 0 + j = len(nums)-1 + while i <= j: + m = (i+j)//2 + if nums[m] <= target: + i = m + 1 else: - l = mid + 1 - return ans \ No newline at end of file + j = m - 1 + return j \ No newline at end of file