2021春季每日一题 【week1 未完结】
生活随笔
收集整理的這篇文章主要介紹了
2021春季每日一题 【week1 未完结】
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
目錄
- 92. 反轉鏈表 II【難度: 中 / 知識點: 鏈表】
- 35. 反轉鏈表【難度: 中 / 知識點: 鏈表】
- 1603. 設計停車系統 【難度: 簡單 / 知識點: 模擬】
- 3267. 小明上學【難度: 簡單 / 知識點: 模擬】
- 150. 逆波蘭表達式求值【未完成】
- 3302. 表達式求值【未完成】
- 73. 矩陣置零 【難度: 一般 / 知識點: 思維 】
- 3174. 旋轉【難度:簡單 / 知識點: 找規律】
92. 反轉鏈表 II【難度: 中 / 知識點: 鏈表】
/*** 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* reverseBetween(ListNode* head, int left, int right) {ListNode* p=new ListNode(-1); p->next=head;ListNode* ans=p;for(int i=0;i<left-1;i++) p=p->next;auto a=p->next,b=a->next;for(int i=0;i<right-left;i++){auto temp=b->next;b->next=a;a=b;b=temp;}p->next->next=b;p->next=a;return ans->next;} };35. 反轉鏈表【難度: 中 / 知識點: 鏈表】
/*** Definition for singly-linked list.* struct ListNode {* int val;* ListNode *next;* ListNode(int x) : val(x), next(NULL) {}* };*/ class Solution { public:ListNode* reverseList(ListNode* head) {ListNode *ans=nullptr;while(head){auto temp=head->next;head->next=ans;ans=head;head=temp;}return ans;} };1603. 設計停車系統 【難度: 簡單 / 知識點: 模擬】
class ParkingSystem { public:vector<int> cnt;ParkingSystem(int big, int medium, int small) {cnt={big,medium,small};}bool addCar(int carType) {int t=carType-1;if(cnt[t]>=1){cnt[t]--;return true;}return false;} };/*** Your ParkingSystem object will be instantiated and called as such:* ParkingSystem* obj = new ParkingSystem(big, medium, small);* bool param_1 = obj->addCar(carType);*/3267. 小明上學【難度: 簡單 / 知識點: 模擬】
#include<bits/stdc++.h> using namespace std; int main(void) {int r,y,g; cin>>r>>y>>g;int n; cin>>n;int sum=0;while(n--){int k,s; cin>>k>>s;if(k==3) continue;else if(k==1) sum+=s;else if(k==2) sum+=r+s;else sum+=s;}cout<<sum<<endl;return 0; }150. 逆波蘭表達式求值【未完成】
3302. 表達式求值【未完成】
73. 矩陣置零 【難度: 一般 / 知識點: 思維 】
class Solution { public:void setZeroes(vector<vector<int>>& ve) {map<int,int>mp1,mp2;for(int i=0;i<ve.size();i++){for(int j=0;j<ve[i].size();j++){if(!ve[i][j]) mp1[i]++,mp2[j]++;}}for(int i=0;i<ve.size();i++){for(int j=0;j<ve[i].size();j++){if(mp1[i]||mp2[j]) ve[i][j]=0;}}} };3174. 旋轉【難度:簡單 / 知識點: 找規律】
#include<bits/stdc++.h> using namespace std; const int N=1e2+10; int a[N][N],b[N][N],n,m; int main(void) {cin>>n>>m;for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)cin>>a[i][j];for(int i=1;i<=n;i++)for(int j=1;j<=m;j++) b[j][n-i+1]=a[i][j];for(int i=1;i<=m;i++){for(int j=1;j<=n;j++) cout<<b[i][j]<<" ";cout<<endl;}return 0; }總結
以上是生活随笔為你收集整理的2021春季每日一题 【week1 未完结】的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 第六章 基础算法
- 下一篇: 2021春季每日一题 【week2 未完