提交 514e9a7c 编写于 作者: 每日一练社区's avatar 每日一练社区

update leetcode and lanqiao markdown style

上级 fc1db5ce
......@@ -26,7 +26,9 @@
<p>以下错误的选项是?</p>
## aop
### before
```cpp
#include <bits/stdc++.h>
using namespace std;
......@@ -42,11 +44,13 @@ struct TreeNode
};
```
### after
```cpp
```
## 答案
```cpp
class Solution
{
......
......@@ -33,7 +33,9 @@
<p>以下错误的选项是?</p>
## aop
### before
```cpp
#include <bits/stdc++.h>
using namespace std;
......@@ -49,11 +51,13 @@ struct TreeNode
};
```
### after
```cpp
```
## 答案
```cpp
class Solution
{
......
......@@ -28,7 +28,9 @@
<p>以下错误的选项是?</p>
## aop
### before
```cpp
#include <bits/stdc++.h>
using namespace std;
......@@ -44,11 +46,13 @@ struct TreeNode
};
```
### after
```cpp
```
## 答案
```cpp
class Solution
{
......
# 分数到小数
<p>给定两个整数,分别表示分数的分子 <code>numerator</code> 和分母 <code>denominator</code>,以 <strong>字符串形式返回小数</strong></p>
<p>如果小数部分为循环小数,则将循环的部分括在括号内。</p>
......@@ -56,12 +57,15 @@
<p>以下错误的选项是?</p>
## aop
### before
```cpp
#include <bits/stdc++.h>
using namespace std;
```
### after
```cpp
int main()
{
......@@ -75,6 +79,7 @@ int main()
```
## 答案
```cpp
class Solution
{
......
......@@ -51,12 +51,15 @@
<p>以下错误的选项是?</p>
## aop
### before
```cpp
#include <bits/stdc++.h>
using namespace std;
```
### after
```cpp
int main()
{
......@@ -76,6 +79,7 @@ int main()
```
## 答案
```cpp
class Solution
{
......
......@@ -44,12 +44,15 @@
<p>以下错误的选项是?</p>
## aop
### before
```cpp
#include <bits/stdc++.h>
using namespace std;
```
### after
```cpp
int main()
{
......@@ -64,6 +67,7 @@ int main()
```
## 答案
```cpp
class Solution
{
......
# 最长连续序列
<p>给定一个未排序的整数数组 <code>nums</code> ,找出数字连续的最长序列(不要求序列元素在原数组中连续)的长度。</p>
<p>请你设计并实现时间复杂度为 <code>O(n)</code><em> </em>的算法解决此问题。</p>
......@@ -31,12 +32,15 @@
<p>以下错误的选项是?</p>
## aop
### before
```cpp
#include <bits/stdc++.h>
using namespace std;
```
### after
```cpp
int main()
{
......@@ -50,6 +54,7 @@ int main()
```
## 答案
```cpp
class Solution
{
......
# 被围绕的区域
给你一个 <code>m x n</code> 的矩阵 <code>board</code> ,由若干字符 <code>'X'</code><code>'O'</code> ,找到所有被 <code>'X'</code> 围绕的区域,并将这些区域里所有的 <code>'O'</code><code>'X'</code> 填充。
<div class="original__bRMd">
<div>
......@@ -35,12 +36,15 @@
<p>以下错误的选项是?</p>
## aop
### before
```cpp
#include <bits/stdc++.h>
using namespace std;
```
### after
```cpp
int main()
{
......@@ -59,6 +63,7 @@ int main()
```
## 答案
```cpp
class Solution
{
......
# 路径总和
<p>给你二叉树的根节点 <code>root</code> 和一个表示目标和的整数 <code>targetSum</code> ,判断该树中是否存在 <strong>根节点到叶子节点</strong> 的路径,这条路径上所有节点值相加等于目标和 <code>targetSum</code></p>
<p><strong>叶子节点</strong> 是指没有子节点的节点。</p>
......@@ -39,7 +40,9 @@
<p>以下错误的选项是?</p>
## aop
### before
```cpp
#include <bits/stdc++.h>
using namespace std;
......@@ -55,11 +58,13 @@ struct TreeNode
};
```
### after
```cpp
```
## 答案
```cpp
其他三个都是错的
```
......
# 路径总和 II
<p>给你二叉树的根节点 <code>root</code> 和一个整数目标和 <code>targetSum</code> ,找出所有 <strong>从根节点到叶子节点</strong> 路径总和等于给定目标和的路径。</p>
<p><strong>叶子节点</strong> 是指没有子节点的节点。</p>
......@@ -43,7 +44,9 @@
<p>以下错误的选项是?</p>
## aop
### before
```cpp
#include <bits/stdc++.h>
using namespace std;
......@@ -60,11 +63,13 @@ struct TreeNode
```
### after
```cpp
```
## 答案
```cpp
class Solution
{
......
# 二叉树的序列化与反序列化
<p>序列化是将一个数据结构或者对象转换为连续的比特位的操作,进而可以将转换后的数据存储在一个文件或者内存中,同时也可以通过网络传输到另一个计算机环境,采取相反方式重构得到原数据。</p>
<p>请设计一个算法来实现二叉树的序列化与反序列化。这里不限定你的序列 / 反序列化算法执行逻辑,你只需要保证一个二叉树可以被序列化为一个字符串并且将这个字符串反序列化为原始的树结构。</p>
......@@ -47,7 +48,9 @@
<p>以下错误的选项是?</p>
## aop
### before
```cpp
#include <bits/stdc++.h>
using namespace std;
......@@ -63,11 +66,13 @@ struct TreeNode
};
```
### after
```cpp
```
## 答案
```cpp
class Codec
{
......
# 二叉搜索树迭代器
实现一个二叉搜索树迭代器类<code>BSTIterator</code> ,表示一个按中序遍历二叉搜索树(BST)的迭代器:
<div class="original__bRMd">
<div>
......@@ -59,7 +60,9 @@ bSTIterator.hasNext(); // 返回 False
<p>以下错误的选项是?</p>
## aop
### before
```cpp
#include <bits/stdc++.h>
using namespace std;
......@@ -75,6 +78,7 @@ struct TreeNode
};
```
### after
```cpp
/**
* Your BSTIterator object will be instantiated and called as such:
......@@ -85,6 +89,7 @@ struct TreeNode
```
## 答案
```cpp
class BSTIterator
{
......
# 实现 Trie (前缀树)
<p><strong><a href="https://baike.baidu.com/item/字典树/9825209?fr=aladdin" target="_blank">Trie</a></strong>(发音类似 "try")或者说 <strong>前缀树</strong> 是一种树形数据结构,用于高效地存储和检索字符串数据集中的键。这一数据结构有相当多的应用情景,例如自动补完和拼写检查。</p>
<p>请你实现 Trie 类:</p>
......@@ -44,17 +45,21 @@ trie.search("app"); // 返回 True
<p>以下错误的选项是?</p>
## aop
### before
```cpp
#include <bits/stdc++.h>
using namespace std;
```
### after
```cpp
```
## 答案
```cpp
class TrieNode
{
......
......@@ -8,12 +8,15 @@
<p>以下错误的选项是?</p>
## aop
### before
```cpp
#include <bits/stdc++.h>
using namespace std;
```
### after
```cpp
// Your Solution object will be instantiated and called as such:
// Solution solution;
......@@ -21,6 +24,7 @@ using namespace std;
```
## 答案
```cpp
class Solution
{
......
# 扁平化嵌套列表迭代器
<p>给你一个嵌套的整数列表 <code>nestedList</code> 。每个元素要么是一个整数,要么是一个列表;该列表的元素也可能是整数或者是其他列表。请你实现一个迭代器将其扁平化,使之能够遍历这个列表中的所有整数。</p>
<p>实现扁平迭代器类 <code>NestedIterator</code></p>
......@@ -49,7 +50,9 @@ return res</pre>
<p>以下错误的选项是?</p>
## aop
### before
```cpp
#include <bits/stdc++.h>
using namespace std;
......@@ -72,11 +75,13 @@ public:
};
```
### after
```cpp
```
## 答案
```cpp
class NestedIterator
{
......
# 按要求补齐数组
<p>给定一个已排序的正整数数组 <em>nums,</em>和一个正整数&nbsp;<em>n 。</em>&nbsp;<code>[1, n]</code>&nbsp;区间内选取任意个数字补充到&nbsp;<em>nums&nbsp;</em>中,使得&nbsp;<code>[1, n]</code>&nbsp;区间内的任何数字都可以用&nbsp;<em>nums&nbsp;</em>中某几个数字的和来表示。请输出满足上述要求的最少需要补充的数字个数。</p>
<p><strong>示例&nbsp;1:</strong></p>
......@@ -27,13 +28,16 @@
<p>以下错误的选项是?</p>
## aop
### before
```cpp
#include <bits/stdc++.h>
using namespace std;
```
### after
```cpp
int main()
{
......@@ -48,6 +52,7 @@ int main()
```
## 答案
```cpp
class Solution
{
......
......@@ -45,12 +45,15 @@
<p>以下错误的选项是?</p>
## aop
### before
```cpp
#include <bits/stdc++.h>
using namespace std;
```
### after
```cpp
int main()
{
......@@ -64,6 +67,7 @@ int main()
```
## 答案
```cpp
class Solution
{
......
# 去除重复字母
<p>给你一个字符串 <code>s</code> ,请你去除字符串中重复的字母,使得每个字母只出现一次。需保证 <strong>返回结果的字典序最小</strong>(要求不能打乱其他字符的相对位置)。</p>
<p><strong>注意:</strong>该题与 1081 <a href="https://leetcode-cn.com/problems/smallest-subsequence-of-distinct-characters">https://leetcode-cn.com/problems/smallest-subsequence-of-distinct-characters</a> 相同</p>
......@@ -30,12 +31,15 @@
<p>以下错误的选项是?</p>
## aop
### before
```cpp
#include <bits/stdc++.h>
using namespace std;
```
### after
```cpp
int main()
{
......@@ -49,6 +53,7 @@ int main()
```
## 答案
```cpp
class Solution
......
# 拼接最大数
<p>给定长度分别为&nbsp;<code>m</code>&nbsp;&nbsp;<code>n</code>&nbsp;的两个数组,其元素由&nbsp;<code>0-9</code>&nbsp;构成,表示两个自然数各位上的数字。现在从这两个数组中选出 <code>k (k &lt;= m + n)</code>&nbsp;个数字拼接成一个新的数,要求从同一个数组中取出的数字保持其在原数组中的相对顺序。</p>
<p>求满足该条件的最大数。结果返回一个表示该最大数的长度为&nbsp;<code>k</code>&nbsp;的数组。</p>
......@@ -35,12 +36,15 @@ k = <code>3</code>
<p>以下错误的选项是?</p>
## aop
### before
```cpp
#include <bits/stdc++.h>
using namespace std;
```
### after
```cpp
int main()
{
......@@ -57,6 +61,7 @@ int main()
```
## 答案
```cpp
class Solution
{
......
......@@ -273,17 +273,47 @@ def modify_config_and_dir_name_new():
for idx, tem_dir in enumerate(exercises_dirs):
config_path = os.path.join(tem_dir, 'config.json')
solution_md_path = os.path.join(tem_dir, 'solution.md')
if dir == "data/1.算法初阶":
title = tem_dir.split('/')[-1].split('.')[-1]
else:
title = tem_dir.split('/')[-1].split('-')[-1]
with open(solution_md_path, 'r', encoding='utf-8') as f:
solution_md_data = f.read()
print(config_path)
with open(config_path, 'r', encoding='utf-8') as f:
config_data = json.load(f)
del config_data['title']
config_data_json = json.dumps(config_data, ensure_ascii=False, indent=2)
print(config_data_json)
if solution_md_data.find('# {}\n\n'.format(title)) == -1:
solution_md_data = solution_md_data.replace('# {}'.format(title), '# {}\n'.format(title))
print(tem_dir)
if solution_md_data.find('## aop\n\n') == -1:
solution_md_data = solution_md_data.replace('## aop', '## aop\n')
if solution_md_data.find('## 答案\n\n') == -1:
solution_md_data = solution_md_data.replace('## 答案', '## 答案\n')
if solution_md_data.find('## 选项\n\n') == -1:
solution_md_data = solution_md_data.replace('## 选项', '## 选项\n')
if solution_md_data.find('### before\n\n') == -1:
solution_md_data = solution_md_data.replace('### before', '### before\n')
with open(config_path, 'w', encoding='utf-8') as f:
f.write(config_data_json)
if solution_md_data.find('### after\n\n') == -1:
solution_md_data = solution_md_data.replace('### after', '### after\n')
if solution_md_data.find('\n\n```cpp') == -1:
solution_md_data = solution_md_data.replace('```cpp', '\n```cpp')
with open(solution_md_path, 'w', encoding='utf-8') as f:
f.write(solution_md_data)
# with open(config_path, 'r', encoding='utf-8') as f:
# config_data = json.load(f)
# del config_data['title']
# config_data_json = json.dumps(config_data, ensure_ascii=False, indent=2)
# print(config_data_json)
# with open(config_path, 'w', encoding='utf-8') as f:
# f.write(config_data_json)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册