2020年12月4日leetcode每日一題
思路
抄的leetcode,今天比較忙,明天補上
程式碼
struct dilinklist
{
int endval;
int len;
struct dilinklist *prenode;
struct dilinklist *nextnode;
}listnode;
int Addlen(struct dilinklist *p , int key , int keynum)
{
while(p->prenode != NULL && p->endval == key - 1 && keynum > 0)
{
p->endval = key;
++p->len;
keynum--;
p = p->prenode;
}
return keynum;
}
struct dilinklist *setnewnode(struct dilinklist *p , int key , int keynum)
{
while(keynum > 0)
{
struct dilinklist *s = (struct dilinklist*)malloc(sizeof(struct dilinklist));
s->endval = key;
s->len = 1;
s->prenode = p;
p->nextnode = s;
s->nextnode = NULL;
p = s;
keynum--;
}
return p;
}
bool isPossible(int* nums, int numsSize){
if(numsSize < 3) return false;
struct dilinklist *head = (struct dilinklist*)malloc(sizeof(struct dilinklist));
head->prenode = NULL;
head->endval = __WINT_MIN__;
head->len = 3;
struct dilinklist *p = (struct dilinklist*)malloc(sizeof(struct dilinklist));//p始終指向表的結尾
p->endval = nums[0];
p->len = 1;
p->prenode = head;
head->nextnode = p;
p->nextnode = NULL;
for(int i = 1 ; i < numsSize ;++i)
{
int count = 1;
int x = nums[i];
for(;i < numsSize - 1 && nums[i+1] == nums[i] ; ++i)
++count;
if((count = Addlen(p , x , count)))//將count個數值為x的數字併到已有的子序列中,返回多餘的數字
p = setnewnode(p , x , count);//根據多餘的數字建立新的子序列;
}
//遍歷表,如果有len<3的情況,輸出false
while(p->prenode != NULL)
{
if(p->len < 3) return false;
//printf("%d %d \n" , p->endval,p->len);
p = p->prenode;
}
return true;
}
相關文章
- leetcode每日一題LeetCode每日一題
- Leetcode每日一題(1)LeetCode每日一題
- LeetCode 2024/6 每日一題 合集LeetCode每日一題
- LeetCode 每日一題「判定字元是否唯一」LeetCode每日一題字元
- LeetCode每日一題: 找不同(No.389)LeetCode每日一題
- LeetCode每日一題: 移除元素(No.27)LeetCode每日一題
- LeetCode每日一題: 移動零(No.283)LeetCode每日一題
- LeetCode每日一題:迴文數(No.9)LeetCode每日一題
- LeetCode每日一題:兩數之和(No.1)LeetCode每日一題
- LeetCode每日一題:自除數(No.728)LeetCode每日一題
- LeetCode每日一題:Nim遊戲(No.292)LeetCode每日一題遊戲
- 75. Sort Colors(Leetcode每日一題-2020.10.07)LeetCode每日一題
- LeetCode每日一題: 排列硬幣(No.441)LeetCode每日一題
- LeetCode每日一題: 各位相加(No.258)LeetCode每日一題
- LeetCode每日一題:求眾數(No.169)LeetCode每日一題
- LeetCode每日一題:爬樓梯(No.70)LeetCode每日一題
- 【LeetCode】每日一題164. 最大間距LeetCode每日一題
- Leetcode每日一題:面試題16.19.水域大小LeetCode每日一題面試題
- leetcode每日一題刷題記錄(10.26-10.30)LeetCode每日一題
- LeetCode每日一題:整數反轉(No.7)LeetCode每日一題
- LeetCode每日一題: 路徑總和(No.112)LeetCode每日一題
- LeetCode每日一題:最長公共字首(No.14)LeetCode每日一題
- 【leetcode】(每日一題 771 寶石與石頭)LeetCode每日一題
- LeetCode每日一題 (32)1. 兩數之和LeetCode每日一題
- 【每日一題-leetcode】416. 分割等和子集每日一題LeetCode
- 18. 4Sum(Leetcode每日一題-2020.10.05)LeetCode每日一題
- LeetCode每日一題: 旋轉陣列(No.189)LeetCode每日一題陣列
- LeetCode每日一題: 猜數字大小(No.374)LeetCode每日一題
- LeetCode每日一題: 搜尋插入位置(No.35)LeetCode每日一題
- LeetCode每日一題: 轉置矩陣(No.867)LeetCode每日一題矩陣
- LeetCode:每日一題:27. 移除元素 ——————簡單LeetCode每日一題
- 【js】Leetcode每日一題-葉子相似的樹JSLeetCode每日一題
- 976. Largest Perimeter Triangle(Leetcode每日一題-2020.11.29)LeetCode每日一題
- 135. Candy(Leetcode每日一題-2020.12.24)--抄答案LeetCode每日一題
- LeetCode每日一題: 按奇偶排序陣列(No.905)LeetCode每日一題排序陣列
- LeetCode每日一題: 檸檬水找零(No.860)LeetCode每日一題
- LeetCode每日一題: 僅僅反轉字母(No.917)LeetCode每日一題
- LeetCode每日一題:斐波那契數(No.509)LeetCode每日一題