自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(317)
  • 资源 (2)
  • 收藏
  • 关注

原创 剑指 Offer 60. n个骰子的点数(c++)

#include<iostream>using namespace std;#include<vector>class Solution {public: vector<double> dicesProbability(int n) { //因为最后的结果只与前一个动态转移数组有关,所以这里只需要设置一个一维的动态转移数组 //原本dp[i][j]表示的是前i个骰子的点数之和为j的概率,现在只需要最后的状态的数组,所以就.

2022-04-18 11:18:30 140

原创 31. 下一个排列(c++)

class Solution {public: void nextPermutation(vector<int>& nums) { int i = nums.size()-2; //1.首先从后向前查找第一个顺序对 (i,i+1),满足 a[i] < a[i+1]。这样「较小数」即为a[i]。此时 [i+1,n)必然是下降序列。 while(i >= 0 && nums[i] >= num...

2022-04-15 10:42:44 797

原创 17. 电话号码的字母组合(c++)

class Solution {public: vector<string>res;//存结果 string temp; //哈希存数据 unordered_map<char,string> phone_map { {'2',"abc"}, {'3',"def"}, {'4',"ghi"}, {'5',"jkl"}, {'6',"mno"}, {'7'..

2022-04-14 11:19:49 1420

原创 最大最小频率的整数的差(python)

小明最近经常会思考一些关于整数的问题。今天他想到这么一个问题:现在有n个整数,其中有些整数相同,也有一些整数不相同。首先需要找出其中出现次数最多的整数,如果出现次数最多的整数不唯一,则找出其中值最大的整数。记为M;然后再找出其中出现次数最少的整数,如果出现次数最少的整数不唯一,则找出其中值最小的整数,记为N;最后计算M和N的差,即输出(M-N)。 请你编写一个程序帮助小明解决这个问题。输入描述单组输入。第1行包含一个正整数n,表示输入的整数个数。(n<=10^5)第2行包含n个整数,两两之间用空格

2022-04-12 21:08:33 676

原创 子查询(SQL)

三种写法:#1.#select cust_id from Orders left join OrderItems using(order_num)#where item_price >= 10#2.# select cust_id from Orders, OrderItems# where Orders.order_num = OrderItems.order_num# and item_price >= 10#3.select cust_id from Orders..

2022-04-12 17:29:08 370

原创 BM3 链表中的节点每k个一组翻转(c++)

方法一 模拟法将一条链表分块分为链表长度/k块链表,如果处不尽则说明后面会有剩下的那一块是不满长度为k的。在最初的时候需要定义两个NodeList表示res(结果)和 now(当前所到达的结果链表的位置)。之后遍历块的长度,对每一个链表块进行翻转,再翻转完后将完成的链表插入到now链表的下一个,再将now链表更新到最前即可。/** * struct ListNode { * int val; * struct ListNode *next; * }; */class Solution .

2022-04-12 16:48:36 1140

原创 HJ32 密码截取(c++/最长回文子串)

一、暴力解:O(N^3)#include<iostream>#include<string>using namespace std;//判断是否为回文串bool is_palindrome(string s){ if(s.size() == 1){ return true; } int i = 0; int j = s.size()-1; while(i < j){ if(s[i] != s[..

2022-04-12 10:57:23 375

原创 SQL 分组查询(group by)

select order_num,count(order_num) as order_linesfrom OrderItems group by order_numorder by order_linesselect vend_id,min(prod_price) as cheapest_itemfrom Productsgroup by vend_idorder by cheapest_itemselect order_num from OrderItemsgroup by .

2022-04-08 17:30:42 678

原创 HJ17 坐标移动(c++/python)

c++:#include<iostream>#include<vector>#include<string>using namespace std;int main(){ string s; vector<string>temp; while(cin >> s){ int sublen = 0; for(int i = 0; i < s.size(); i++){ ..

2022-04-08 16:39:05 1547

原创 最长上升子序列(c++)

class Solution {public: /** * retrun the longest increasing subsequence * @param arr int整型vector the array * @return int整型vector */ vector<int> LIS(vector<int>& arr) { // write code here vecto...

2022-04-08 16:15:22 646

原创 NC109 岛屿数量(c++/DFS/BFS)

深度优先搜索(dfs):// 栈实现深度优先遍历 dfsclass Solution {public: /** * 判断岛屿数量 * @param grid char字符型vector<vector<>> * @return int整型 */ int solve(vector<vector<char> >& grid) { // write code here ..

2022-04-07 16:40:16 1029

原创 汇总数据(mysql)

select sum(quantity) as items_ordered from OrderItemsselect sum(quantity)from OrderItemswhere prod_id = 'BR01'select max(prod_price) as max_pricefrom Products where prod_price <= 10

2022-04-07 15:10:36 93

原创 使用函数处理数据(mysql)

SQL22 顾客登录名select cust_id,cust_name,upper(concat(left(cust_contact,2),left(cust_city,3))) as user_loginfrom Customersselect order_num,order_datefrom Orders#where order_date like '%2020-01%'#where year(order_date) = 2020 and month(order_date) = 1

2022-04-07 14:55:21 459

原创 创建计算字段(SQL)

select vend_id,vend_name as vname,vend_address as vaddress,vend_city as vcity from Vendors order by vnameselect prod_id,prod_price,round(prod_price*0.9,3) as sale_pricefrom Products

2022-04-07 11:03:06 274

原创 检索产品名称和描述(SQL)

select prod_name, prod_desc from Productswhere prod_desc like "%toy%"select prod_name,prod_descfrom Products where prod_desc not like "%toy%"order by prod_nameselect prod_name,prod_descfrom Products where prod_desc like "%toy%"and prod_desc .

2022-04-05 21:24:42 693

原创 SQL14 返回所有价格在 3美元到 6美元之间的产品的名称和价格

SQL14 返回所有价格在 3美元到 6美元之间的产品的名称和价格select prod_name, prod_pricefrom Products#where prod_price between 3 and 6where prod_price >= 3 and prod_price <= 6order by prod_price

2022-04-05 20:36:23 409

原创 SQL13 检索并列出已订购产品的清单

SQL13 检索并列出已订购产品的清单代码:select order_num, prod_id, quantity from OrderItems where quantity >= 100 and prod_id in ("BR01","BR02","BR03")

2022-04-05 20:26:19 503

原创 SQL12 检索供应商名称(mysql)

SQL12 检索供应商名称代码如下:select vend_name from Vendors where vend_country = 'USA' and vend_state = 'CA'

2022-04-05 20:12:40 1907

原创 22. 括号生成(c++)

当前左右括号都有小于n个可以使用的时候,才产生分支;产生左分支的时候,只看当前是否还有左括号可以使用;产生右分支的时候,还受到左分支的限制,右边剩余可以使用的括号数量一定得在严格小于左边剩余的数量的时候,才可以产生分支;在左边和右边剩余的括号数都等于 n的时候结算。一、#include<iostream>#include<stdio.h>#include<vector>#include<string>using namespace st..

2022-03-29 10:49:18 3048

原创 122. 买卖股票的最佳时机 II(c++/动态规划)

class Solution {public: int maxProfit(vector<int>& prices) { int n = prices.size(); int dp[n][2]; dp[0][0] = 0;//没有股票 dp[0][1] = -prices[0];//持有股票 for(int i = 1; i < n; i++){ dp[i][0]...

2022-03-26 20:30:09 1056

原创 64. 最小路径和(c++)

class Solution {public: int minPathSum(vector<vector<int>>& grid) { if(grid.size() == 0 && grid[0].size() == 0){ return 0; } int n = grid.size(); int m = grid[0].size(); vec..

2022-03-26 20:05:04 1329

原创 300. 最长递增子序列(c++)

class Solution {public: int lengthOfLIS(vector<int>& nums) { int n = nums.size(); vector<int>dp(n,0); int max_len = 0; for(int i = 0; i < n; i++){ dp[i] = 1; for(int j = 0; j..

2022-03-25 11:37:26 1084

原创 895. 最大频率栈(c++)

#include<iostream>#include<unordered_map>#include<stack>#include<string>using namespace std;class FreqStack{public: FreqStack(){ } void push(int val){ ++m[val]; max_f = max(max_f,m[val]);//更新最大频率 ..

2022-03-24 10:23:34 785

原创 BM30 二叉搜索树与双向链表(c++)

解题思路:/*struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) { }};*/class Solution {public: vector<TreeNode*>treelist; TreeNode* Convert(TreeNode* pRootOfTre.

2022-03-24 10:01:14 1438

原创 BM14 链表的奇偶重排(c++)

/** * struct ListNode { * int val; * struct ListNode *next; * ListNode(int x) : val(x), next(nullptr) {} * }; */class Solution {public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param head ListNode类 * @return.

2022-03-23 16:42:41 1262

原创 HJ99 自守数(c++/python)

c++:#include<iostream>using namespace std;int main(){ int n; cin >> n; int count = 0; for(int i = 0; i <= n; i++){ int j = i; int pow_i = i*i; while(j){ if(j%10 == pow_i%10){ .

2022-03-21 21:11:59 793

原创 HJ108 求最小公倍数(c++)

#include<iostream>using namespace std;int main(){ int n,m; cin >> n; cin >> m; int min_v = min(n,m); int res = 1; for(int i = 2; i < min_v; i++){ while(n % i == 0 && m % i == 0){ .

2022-03-21 20:20:29 562

原创 NC128 接雨水问题(c++)

class Solution {public: /** * max water * @param arr int整型vector the array * @return long长整型 */ long long maxWater(vector<int>& arr) { // write code here int n = arr.size(); if(n < 2){ ..

2022-03-16 20:38:52 895

原创 NC32 求平方根(c++)

class Solution {public: /** * * @param x int整型 * @return int整型 */ int sqrt(int x) { // write code here if(x <= 1){ return x; } int left = 1; int right = x;//左右边界 .

2022-03-16 19:38:27 551

原创 阿里笔试题目(c++)

阿里面试题题目描述小红拿到了一个n行m列的矩阵,矩阵中用1表示人0表示聚光灯。每个聚光灯可以朝着上、下、左、右四个方向照射(照射的距离是无穷大的),若某个方向上至少有一个人,那么小红就获得了1分。小红想知道,所有的聚光灯一共可以获得多少分?#include<iostream>#include<string>#include<algorithm>#include<bits/stdc++.h>using namespace std;const i

2022-03-15 15:38:12 1266 1

原创 HJ91 走方格的方案数(c++)

#include<iostream>#include<vector>using namespace std;int main(){ int m = 0; int n = 0; while(cin >> n >> m){ vector<vector<int>>res(n+1,vector<int>(m+1,0)); for(int i = 0; i <= .

2022-03-14 15:28:58 620

原创 HJ58 输入n个整数,输出其中最小的k个(c++)

#include<iostream>#include<vector>#include<algorithm>using namespace std;int main(){ int n; vector<int>nums; int a; int k = 0; while(cin >> n){ cin >> k; for(int i = 0; i < n;.

2022-03-14 14:53:21 554

原创 HJ26 字符串排序(c++)

#include<iostream>using namespace std;#include<vector>#include<string>string stringSort(string str){ vector<char>temp;//用一个 char 型的向量存储按规则排序后的字符串中的字母字符 //规则一:英文字母从 A 到 Z 排列,不区分大小写。 //规则二:同一个英文字母的大小写同时存在时,按照输入顺序排列。.

2022-03-14 11:16:42 827

原创 BM23 二叉树的前中后序遍历(c++)

/** * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} * }; */class Solution {public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * ..

2022-03-13 20:48:30 117

原创 BM19 寻找峰值(c++)

class Solution {public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型vector * @return int整型 */ int findPeakElement(vector<int>& nums) { // write code here //关键思想:下...

2022-03-13 20:05:38 1925

原创 BM18 二维数组中的查找(c++)

class Solution {public: bool Find(int target, vector<vector<int> > array) { int m = array.size();//列数 for(int i = 0; i < m; i++){ if(binaryfind(target, array[i])){ return true; }..

2022-03-13 16:46:06 523

原创 BM17 二分查找-I(c++)

class Solution {public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型vector * @param target int整型 * @return int整型 */ int search(vector<int>& nums, int target) { // writ..

2022-03-13 15:23:18 504

原创 BM16 删除有序链表中重复的元素-II(c++)

/** * struct ListNode { * int val; * struct ListNode *next; * }; */class Solution {public: /** * * @param head ListNode类 * @return ListNode类 */ ListNode* deleteDuplicates(ListNode* head) { // write code here..

2022-03-12 22:55:11 529 1

原创 BM15 删除有序链表中重复的元素-I(c++)

/** * struct ListNode { * int val; * struct ListNode *next; * }; */class Solution {public: /** * * @param head ListNode类 * @return ListNode类 */ ListNode* deleteDuplicates(ListNode* head) { // write code here .

2022-03-12 21:09:20 259

原创 BM13 判断一个链表是否为回文结构(c++)

/** * struct ListNode { * int val; * struct ListNode *next; * }; */class Solution {public: /** * * @param head ListNode类 the head * @return bool布尔型 */ bool isPail(ListNode* head) { // write code here L..

2022-03-12 20:56:33 159

MRI data for TSC study

MRI data for TSC study

2022-06-19

18-20年及零几年算法试卷及作业答案.rar

国科大陈玉福算法期末试卷往年题,18-19试卷,以及20年试卷题目回忆,及复习经验分享,还有作业答案噢

2021-01-09

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除