- 博客(11)
- 收藏
- 关注
原创 Leetcode 820. 单词的压缩编码
反向字典序排序,排序后遍历求解class Solution {private: static bool cmp(string& a, string& b) { int ia = a.length() - 1, ib = b.length() - 1; while (ia && ib) { if (a...
2020-03-28 21:12:52
198
原创 Leetcode 面试题 16.03. 交点
class Solution {private: bool NumBetween (int a, int m, int n) { int small = min(m, n), large = max(m, n); return a >= small && a <= large; } bool NumBetwe...
2020-03-26 10:19:22
379
原创 Leetcode 89. 格雷码生成
class Solution {public: vector<int> grayCode(int n) { vector<int> grayList(1 << n, 0); /* if (n == 0) { return grayList; } el...
2020-03-23 23:59:22
231
原创 读取xml文件指定内容
def read_xml(path, tag_name='QW', attribute_name='value'): dom_tree = xml_parse(path) root_node = dom_tree.documentElement tag_list = root_node.getElementsByTagName(tag_name) details =...
2020-03-23 22:56:32
380
原创 斐波那契数列——矩阵快速幂解法
#include <iostream>#include <algorithm>using namespace std; typedef long long ll;const ll mod = 1000000007; struct Matrix { ll num[2][2]; void initial() { num[0][0] ...
2020-03-22 22:18:33
237
原创 PYNLPIR中文分词,生成词云图片
from collections import Counterimport matplotlib.pyplot as pltimport wordcloudimport pynlpirwith open('./paper.txt', encoding='utf-8') as text: contents = text.read()# 分词pynlpir.open() ...
2020-03-22 21:52:52
619
原创 Python 递归读取某文件夹下全部指定后缀名文件
import osdef all_files(path, file_type): # 生成path路径下全部file_type类型文件绝对路径列表 f_list = [] def files_list(father_path): sub_path = os.listdir(father_path) # 读取父路径下全部文件或文件夹名称 ...
2020-03-22 21:24:34
982
原创 算符优先文法——中缀表达式转换为后缀表达式并求值
算符优先文法——中缀表达式转换为后缀表达式并求值根据编译原理相关知识,我们可将整个程序分为三个部分,词法分析,文法分析,后缀表达式计算,在文法分析中会涉及到运算符优先级的判断。接下来我将分模块对代码进行解释,希望可以对读者理解算符优先文法、词法分析有和后缀表达式求值有所帮助。代码可以识别包含括号的基本四则运算和乘方运算,可以识别浮点数,未进行错误运算时的错误处理。运算符优先级如数组sp所示...
2020-03-08 23:15:10
1172
原创 Leetcode 67. 使用栈和全加器实现二进制求和(JAVA)
使用栈和全加器实现二进制求和(JAVA)使用栈实现输入二进制串反序,使用加法器实现每一位求和加法器核心代码:s = a ^ b ^ c; //求和结果c = (a &amp;amp;amp; b) | (a &amp;amp;amp; c) | (b &amp;amp;amp; c); //进位题目: Leetcode 二进制求和给定两个二进制字符串,返回他们的和(用二进制表示)。输入为非空字符串且只包含数字 1 和 0。示例...
2018-11-10 22:21:37
406
原创 Sorting
Sorting#define MAXN 1005 //数组最大长度int num[MAXN]; //待排序数组int n; //数组中元素个数Insertion Sort直接插入排序//设置哨兵num[0], 为在查找插入位置的过程中避免数组下标越界void InsertSort() { int i, j; for (i = 2; i <= n; i++)
2017-12-28 10:33:15
281
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人