wlyhuat

784

czz
RyanMoriarty
WR.wan

tianxufan
khalil

wlyhuat
2天前

wlyhuat
6天前

wlyhuat
6天前

wlyhuat
1个月前
#include <iostream>
using namespace std;
const int N = 100010;
int stk[N], tt;

int main()
{
int n;
cin >> n;
while (n -- )
{
int x;
scanf("%d", &x);
while (tt && stk[tt] >= x) tt -- ;//如果栈顶元素大于当前待入栈元素，则出栈
if (!tt) printf("-1 ");//如果栈空，则没有比该元素小的值。
else printf("%d ", stk[tt]);//栈顶元素就是左侧第一个比它小的元素。
stk[ ++ tt] = x;
}
return 0;
}



wlyhuat
2个月前
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

bool cmp(vector<int>& a, vector<int>& b) {
return a[1] < b[1];
}
int main() {
int n;
cin>>n;
vector<vector<int>> nums(n, vector<int>(2));
int res = 1;
for(int i = 0; i < n; i++) {
cin>>nums[i][0]>>nums[i][1];
}
sort(nums.begin(), nums.end(), cmp);
int r = nums[0][1];
for(int i = 1; i < nums.size(); i++) {
if(nums[i][0] > r) {
res++;
r = nums[i][1];
}
}
cout<<res<<endl;
return 0;

}


wlyhuat
2个月前
/**
* struct ListNode {
*     int val;
*     ListNode *next;
*     ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
while(q && p) {
q = q -> next;
p = p -> next;
if(q) q = q ->next;
if(q && q == p) {
while(p != q) {
p = p ->next;
q = q ->next;
}
return q;
}
}
return nullptr;

}
};



wlyhuat
2个月前
#include <iostream>
#include <vector>
using namespace std;

int main() {
int n, m;
cin>>n>>m;
int dy[] = {0, 1, 0, -1}, dx[] = {-1, 0, 1, 0}; //右下左上
vector<vector<int>> q(n, vector<int>(m, 0));
int x = 0, y = 0, d = 1;
for(int i = 1; i <= n * m; i++) {
q[x][y] = i;
int a = x + dx[d], b = y + dy[d];
if(a < 0 || a >= n || b < 0 || b >= m || q[a][b]) {
d = (d + 1) % 4;
a = x + dx[d], b = y + dy[d];
}
x = a, y = b;
}

for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
cout<<q[i][j]<<" ";
}
cout<<endl;
}
return 0;

}



wlyhuat
3个月前
class Solution {
public:
vector<int> dailyTemperatures(vector<int>& temperatures) {
stack<int> index;
vector<int> res;
res.push_back(0);
index.push(temperatures.size()-1);
for(int i = temperatures.size() - 2; i >= 0; i--) {
while(index.size() && temperatures[i] >= temperatures[index.top()]) index.pop();
if(index.size() == 0) res.push_back(0);
else res.push_back(index.top() - i);
index.push(i);
}
reverse(res.begin(), res.end());
return res;

}
};


wlyhuat
3个月前
class Solution {
public:
int maxProfit(vector<int>& prices) {
vector<int> dp(prices.size(), 0);
for(int i = 1; i < prices.size(); i++) {
dp[i] = max(prices[i] - prices[i-1] + dp[i-1], 0);
}

int res = 0;
for(int i = 0; i < dp.size(); i++) {
res = max(res, dp[i]);
}
return res;
}
};


wlyhuat
3个月前
class Solution {
public:
string longestPalindrome(string s) {
string res;
for(int i = 0; i < s.size(); i++) {
int l = i - 1, r = i + 1;
while(l >= 0 && r < s.size() && s[l] == s[r]) l--, r++;
if(res.size() < r - l - 1)  res = s.substr(l + 1, r - l - 1);

l = i, r = i + 1;
while(l >= 0 && r < s.size() && s[l] == s[r]) l--, r++;
if(res.size() < r - l - 1)  res = s.substr(l + 1, r - l - 1);
}
return res;
}
};