当前位置:网站首页>Analysis and comparison of leetcode weekly race + acwing weekly race (t4/t3)
Analysis and comparison of leetcode weekly race + acwing weekly race (t4/t3)
2022-07-05 00:57:00 【OpenAll_ Zzz】
AcWing 57 T3
Leetcode Biweekly 80 T4
Preface
The common ground between the two questions lies in the subarray value The definition of ,LC Multiply the sum of subarrays by their length ,AcWing Divide the sum of subarrays by their length ( Average ).
analysis - AcWing T3
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N = 1000010;
int n;
LL s[N];
int stk[N];
int main()
{
scanf("%d", &n);
for(int i = 1; i <= n; i ++)
{
int x;
scanf("%d", &x);
s[i] = s[i - 1] + x - 100;
}
int top = 0,res = 0;
stk[++ top] = 0;
for(int i = 1; i <= n; i ++)
{
if(s[stk[top]] > s[i]) stk[++ top] = i;
else if(s[stk[top]] < s[i])
{
int l = 0, r = top;
while(l < r)
{
int mid = l + r >> 1;
if(s[stk[mid]] < s[i]) r = mid;
else l = mid + 1;
}
res = max(res, i - stk[r]);
}
}
printf("%d\n", res);
return 0;
}
analysis - LeetCode T4
class Solution {
public:
typedef long long LL;
long long countSubarrays(vector<int>& nums, long long k) {
LL res = 0, sum = 0;
for(int i = 0, j = 0; j < nums.size(); j ++)
{
sum += nums[j];
while(sum * (j - i + 1) >= k) sum -= nums[i ++];
res += j - i + 1;
}
return res;
}
};
边栏推荐
- GDB常用命令
- Talking about JVM 4: class loading mechanism
- I was beaten by the interviewer because I didn't understand the sorting
- 《论文笔记》Multi-UAV Collaborative Monocular SLAM
- leetcode494,474
- ORB(Oriented FAST and Rotated BRIEF)
- SAP UI5 应用的主-从-从(Master-Detail-Detail)布局模式的实现步骤
- Getting started with Paxos
- Which financial products with stable income are good
- 【C】 (written examination questions) pointer and array, pointer
猜你喜欢
测试部新来了个00后卷王,上了年纪的我真的干不过了,已经...
初识ROS
FEG founder rox:smartdefi will be the benchmark of the entire decentralized financial market
"Upside down salary", "equal replacement of graduates" these phenomena show that the testing industry has
Call Huawei order service to verify the purchase token interface and return connection reset
SAP UI5 应用的主-从-从(Master-Detail-Detail)布局模式的实现步骤
ORB(Oriented FAST and Rotated BRIEF)
URLs and URIs
Relationship between classes and objects
Huawei employs data management experts with an annual salary of 2million! The 100 billion market behind it deserves attention
随机推荐
P4408 [noi2003] truant children (tree diameter)
URL和URI
那些一门心思研究自动化测试的人,最后都怎样了?
Digital DP template
Innovation leads the direction. Huawei Smart Life launches new products in the whole scene
Les phénomènes de « salaire inversé » et de « remplacement des diplômés » indiquent que l'industrie des tests a...
【纯音听力测试】基于MATLAB的纯音听力测试系统
User login function: simple but difficult
大专学历,33岁宝妈又怎样?我照样销售转测试,月入13k+
程序员SQL数据脚本编码能力弱,BI做不出来怎么办?
Call Huawei order service to verify the purchase token interface and return connection reset
Pycharm professional download and installation tutorial
GDB常用命令
Playwright recording
2022.07.03(LC_6111_统计放置房子的方式数)
Chia Tai International Futures: what is the master account and how to open it?
Detailed explanation of openharmony resource management
There is a new Post-00 exam king in the testing department. I really can't do it in my old age. I have
const、volatile和restrict的作用和用法总结
Applet live + e-commerce, if you want to be a new retail e-commerce, use it!