leetcode 977 题目链接:
https://leetcode.com/problems/squares-of-a-sorted-array/
最终ac代码:(双指针法)
class Solution
{
public:
vector sortedSquares(vector &nums)
{
vector v;
int left = 0;
int right = nums.size() - 1;
while (left
std::vector operator[] 不做越界检查,vector::at 才检查
leetcode 209 题目链接:
https://leetcode.com/problems/minimum-size-subarray-sum/
ac代码:(滑动窗口) 缺点:圈复杂度比较大
class Solution
{
public:
int minSubArrayLen(int target, vector &nums)
{
int wl = 0;
int wr = 0;
int wsum = 0;
int minWlen = INT_MAX;
while (true)
{
if (wsum
双循环版本(复杂度仍然是O(n),圈复杂度降低):
class Solution
{
public:
int minSubArrayLen(int target, vector &nums)
{
int wl = 0;
int wsum = 0;
int minWlen = INT_MAX;
for (int wr = 0; wr = target)
{
int wlen = wr - wl + 1;
if (wlen
leetcode 59
https://leetcode.com/problems/spiral-matrix-ii/
ac代码:
class Solution
{
public:
vector> generateMatrix(int n)
{
vector> v(n);
for (int i = 0; i (n);
}
int square = n * n;
int loopnum = n / 2;
if (n % 2 == 1)
{
v[loopnum][loopnum] = square;
}
int num = 1;
for (int i = 0; i i; --j)
{
v[n - i - 1][j] = num++;
}
for (int j = n - i - 1; j > i; --j)
{
v[j][i] = num++;
}
}
return v;
}
};
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
相关推荐: Auto-GPT 迈向智能体的第一步——从信息增强和上下文理解开始
Auto-GPT 的出现,意味着 AI 已经能够在没有人工干扰的情况下独立地完成目标任务。这个在 GitHub 中不断创造历史的项目,正以惊人的速度发展着、变化着。 这样前沿又带有科幻色彩的技术项目,引起了各方关注,开发者、投资人、媒体人,难掩对 Auto-G…