Leetcode.29
123456789101112131415161718192021class Solution {public: int divide(int x, int y) { // 特判:如果除法溢出,返回2 ^ 31 - 1;只有这种情况ans会溢出 if (x == INT_MIN && y == -1) return INT_MAX; long a = abs(x), b = abs(y), ans = 0; int sign = x < 0 ^ y < 0 ? -1 : 1; while (a >= b) { // 保证被除数>=除数,ans起码有1 long tmp = b, m = 1; while (tmp << 1 <= a) { // 找到最大的小于被除数的除数倍数值 tmp <<= 1; ...
Linux记录
1.常用命令1234567891011121314ls: 列出当前目录下所有文件,蓝色的是文件夹,白色的是普通文件,绿色的是可执行文件pwd: 显示当前路径df -h:查看硬盘使用情况free -h:查看内存使用情况cd XXX: 进入XXX目录下, cd .. 返回上层目录cp XXX YYY:复制mkdir XXX: 创建目录XXXrm XXX: 删除普通文件; rm XXX -r: 删除文件夹mv XXX YYY: 移动touch XXX: 创建一个文件cat XXX: 展示文件XXX中的内容复制文本: Ctrl + insert粘贴文本: Shift + insertag xxx:搜索当前目录下的所有文件,检索xxx字符串
系统状况:
12345678top:查看所有进程的信息df -h:查看硬盘使用情况free -h:查看内存使用情况du -sh:查看当前目录占用的硬盘空间ps aux:查看所有进程kill -9 pid:杀死编号为pid的进程netstat -nt:查看所有网络连接ping www.baidu.com:检查是否连网
2.Tmux1234567891 ...
Leetcode.46 全排列
123456789101112131415161718192021222324252627282930class Solution {public: vector<vector<int>> ans; vector<int> path; vector<bool> st; vector<vector<int>> permute(vector<int>& nums) { path.resize(nums.size(), 0); st.resize(nums.size(), false); dfs(nums, 0); return ans; } void dfs(vector<int>& nums, int u){ if(u == nums.size()){ ans.push_back(path); ...
Leetcode.78 子集
123456789101112131415161718192021222324class Solution {public: vector<vector<int>> res; vector<int> path; int n; vector<vector<int>> subsets(vector<int>& nums) { n = nums.size(); dfs(nums, 0); return res; } void dfs(vector<int>& nums, int u){ //位置u上的数选还是不选 if(u == n){ res.push_back(path); return; } path.push_back(nums[u]); df ...
Leetcode.102 二叉树的层序遍历
12345678910111213141516171819202122class Solution {public: vector<vector<int>> levelOrder(TreeNode* root){ vector<vector<int>> ans; queue<TreeNode*> q; if(root) q.push(root); while(!q.empty()){ int len = q.size(); vector<int> level; while(len --){ auto t = q.front(); q.pop(); level.push_back(t->val); if(t->left) ...
Leetcode.2 两数相加
123456789101112131415161718192021class Solution {//只能从低位往高位加public: ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) { auto dummy = new ListNode(-1), cur = dummy; int t = 0; while(l1 || l2 || t){ if(l1){ t += l1->val; l1 = l1->next; } if(l2){ t += l2->val; l2 = l2->next; } cur->next = new ListNode(t % 1 ...
Leetcode.3
12345678910111213141516class Solution {public: int lengthOfLongestSubstring(string s) { unordered_map<char,int> mp; int res = 0; for(int i = 0, j = 0; i < s.size(); i ++){ mp[s[i]] ++; while(mp[s[i]] > 1){ mp[s[j]] --; j ++; } res = max(res, i - j + 1); } return res; }};
数据分析
案例:学习时间与成绩的关系(线性回归)第1步:导入数据分析库pandas,数据可视化库matplotlib %matplotlib inline是Ipython的魔法函数,其作用是使matplotlib绘制的图像嵌入在juptyer notebook的单元格里
123import pandas as pdimport matplotlib.pyplot as plt%matplotlib inline
第2步:导入数据集1dataset = pd.read_csv('./studentscores.csv')
1type(dataset)
pandas.core.frame.DataFrame
1dataset.shape
(25, 2)
第3步:提取特征提取特征:学习时间 提取标签:学习成绩
12feature_columns = ['Hours']label_column = ['Scores']
12features = dataset[feature_columns]label = dataset ...
搜索技术笔记
搜索技巧
限定关键词: 用双引号””包裹
限定标题: intitle
限定内容: intext
限定网址: inurl
限定网站: site
限定图片大小: imagesize
限定文件类型: filetype
EXCEL
rand() :没有参数,返回的随机数大于等于 0 ,小于 1




