中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當前位置: 首頁 > news >正文

濮陽做網(wǎng)站的公司有哪些谷歌搜索引擎下載

濮陽做網(wǎng)站的公司有哪些,谷歌搜索引擎下載,dw怎么做連接到另外一個網(wǎng)站,做網(wǎng)站多錢● 自己看到題目的第一想法 203.移除鏈表元素 方法一: 思路: 設(shè)置虛擬頭節(jié)點 dummyhead 設(shè)置臨時指針 cur 遍歷 整個鏈表 循環(huán): 如果 cur !nullptr &&cur->next !nullptr 則 遍歷鏈表 否則結(jié)束遍歷 如果 cur->next val 則…

● 自己看到題目的第一想法

203.移除鏈表元素

方法一:

  1. 思路:
    設(shè)置虛擬頭節(jié)點 dummyhead
    設(shè)置臨時指針 cur 遍歷 整個鏈表
    循環(huán):
  • 如果 cur !=nullptr &&cur->next !=nullptr 則 遍歷鏈表 否則結(jié)束遍歷

  • 如果 cur->next == val 則 cur->next = cur->next->next

  • 如果 cur->next !=val 則 cur = cur->next

返回 return dummyhead->next

  1. 注意:用while循環(huán)
  2. 代碼:
/*** 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* removeElements(ListNode* head, int val) {ListNode* dummyhead = new ListNode(0);dummyhead->next = head;ListNode* cur = dummyhead;while(cur !=nullptr &&cur->next !=nullptr){if(cur->next->val == val){cur->next = cur->next->next;}else{cur = cur->next;}}head = dummyhead->next;delete dummyhead;return head;}
};
  1. 運行結(jié)果:
    在這里插入圖片描述

方法二:

  1. 思路:
    直接在原鏈表上操作

    1.頭節(jié)點是val值
    刪除頭節(jié)點 head = head->next;

    2.頭節(jié)點不是val值
    定義一個臨時變量cur 遍歷整個鏈表
    循環(huán) :

  • 如果cur !=nullptr && cur->next !=nullptr 則 遍歷鏈表 否則結(jié)束遍歷

  • 如果 cur->next == val 則 cur->next = cur->next->next

  • 如果 cur->next !=val 則 cur = cur->next

返回 return head;

  1. 注意:

  2. 代碼:

/*** 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* removeElements(ListNode* head, int val) {while(head !=nullptr && head->val == val){head = head->next;}ListNode *cur = head;while(cur !=nullptr && cur->next !=nullptr){if(cur->next->val == val ){cur->next = cur->next->next;}else{cur = cur->next;}}return head;}
};
  1. 運行結(jié)果:

在這里插入圖片描述

707.設(shè)計鏈表

  1. 思路:
  2. 注意:
    cur應(yīng)該指向_dummyhead 還是_dummyhead->next;
    鏈表的構(gòu)造struct 還有 private中 鏈表的 定義
  3. 代碼:
class MyLinkedList {
public:
struct ListNode{int val;ListNode* next ;ListNode(int val): val(val), next(nullptr){}
};MyLinkedList() {_size = 0;_dummyhead = new ListNode(0);}int get(int index) {if(index>(_size-1) || index<0){return -1;}ListNode* cur = _dummyhead;while(index){cur = cur->next;index--;}return cur->next->val;}void addAtHead(int val) {ListNode* newnode = new ListNode(val);newnode->next = _dummyhead->next;_dummyhead->next = newnode;_size++;}void addAtTail(int val) {ListNode* cur = _dummyhead;ListNode* newnode = new ListNode(val);while(cur !=nullptr && cur->next !=nullptr){cur =cur->next;}cur->next = newnode;_size++;}void addAtIndex(int index, int val) {ListNode* newnode = new ListNode(val);if(index<0)  index =0;if(index >_size) return ;ListNode * cur = _dummyhead;while(index--){cur = cur->next;}newnode->next = cur->next;cur->next = newnode;_size++;}void deleteAtIndex(int index) {if(index<0 || index>(_size-1)){return ;}ListNode*cur = _dummyhead;while(index--){cur = cur->next;}cur->next = cur->next->next;_size--;}private:int _size;ListNode* _dummyhead;
};/*** Your MyLinkedList object will be instantiated and called as such:* MyLinkedList* obj = new MyLinkedList();* int param_1 = obj->get(index);* obj->addAtHead(val);* obj->addAtTail(val);* obj->addAtIndex(index,val);* obj->deleteAtIndex(index);*/
  1. 運行結(jié)果:
    在這里插入圖片描述

206.反轉(zhuǎn)鏈表

方法一:

  1. 思路:雙指針
    定義pre= null, cur = head, 臨時變量temp保存 cur->next;
    循環(huán):

     cur != null讓cur->next = pre;   pre = cur; cur = temp;
    

    返回:pre

  2. 注意:

  3. 代碼:

/*** 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* reverseList(ListNode* head) {ListNode* cur = head;ListNode* pre = nullptr;ListNode* tmp ;while(cur !=nullptr){tmp = cur->next;cur->next = pre ;pre  =cur;cur = tmp;}return pre;}
};
  1. 運行結(jié)果
    在這里插入圖片描述
    方法二:

  2. 思路:遞歸法:

    先完成翻轉(zhuǎn)的第一步:
    確定終止條件: cur==null 返回 pre
    循環(huán)體: cur ->next = pre
    遞歸下去 return reverse(cur, tmp)

  3. 注意:

  4. 代碼:

/*** 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* reverse(ListNode* pre, ListNode* cur ){if(cur == nullptr) return pre;ListNode* temp;temp = cur->next;cur->next = pre;return reverse(cur, temp);}ListNode* reverseList(ListNode* head) {return reverse(nullptr, head);}
};
  1. 運行結(jié)果:
    在這里插入圖片描述
http://www.risenshineclean.com/news/50576.html

相關(guān)文章:

  • 特效相冊網(wǎng)站源碼百度app官網(wǎng)下載安裝
  • 做網(wǎng)站實現(xiàn)登陸功能十八大禁用黃app入口
  • 做教育app的網(wǎng)站有哪些百度最新版下載
  • 潮州網(wǎng)絡(luò)推廣seo課程培訓(xùn)班
  • 百度小程序登錄入口商品標題seo是什么意思
  • 墾利網(wǎng)頁定制汕頭seo外包機構(gòu)
  • 學(xué)做美食視頻在哪個網(wǎng)站短信廣告投放軟件
  • 企業(yè)為什么要網(wǎng)站建設(shè)網(wǎng)推平臺有哪些
  • 廣告設(shè)計軟件手機版朝陽seo推廣
  • 正日商務(wù)做網(wǎng)站多少錢應(yīng)用商店下載安裝
  • 汕頭網(wǎng)站制作哪里好優(yōu)化網(wǎng)站標題名詞解釋
  • 網(wǎng)頁制作工作網(wǎng)站提高工作效率的軟件
  • 好用的搜索引擎上海網(wǎng)站排名seo公司
  • 建網(wǎng)站的公司起什么名好江蘇seo技術(shù)教程
  • 惠州網(wǎng)站建設(shè)網(wǎng)站app拉新平臺
  • 衢州建筑裂縫加固seo推廣軟件排行榜
  • 如何做好網(wǎng)站建設(shè)的設(shè)計布局鄭州粒米seo顧問
  • 做爰全過程免費狐貍網(wǎng)站阿里巴巴國際貿(mào)易網(wǎng)站
  • 網(wǎng)站做配置文件的作用專業(yè)做網(wǎng)站設(shè)計
  • 圖片點開是網(wǎng)站怎么做在線外鏈推廣
  • 天津網(wǎng)站建設(shè)技術(shù)托管今日新聞大事件
  • 設(shè)計蘋果手機的網(wǎng)站長春seo代理
  • 網(wǎng)上購物商城網(wǎng)站建設(shè)畢業(yè)設(shè)計網(wǎng)絡(luò)平臺推廣運營有哪些平臺
  • 做網(wǎng)站的邊框素材重慶seo網(wǎng)絡(luò)推廣關(guān)鍵詞
  • 常州本地招聘網(wǎng)站怎么讓付費網(wǎng)站免費
  • gps定位網(wǎng)站建設(shè)網(wǎng)絡(luò)營銷策劃書總結(jié)
  • 網(wǎng)站建設(shè)預(yù)算策劃湖南seo優(yōu)化
  • 推廣網(wǎng)站怎么建設(shè)新東方線下培訓(xùn)機構(gòu)官網(wǎng)
  • 網(wǎng)頁設(shè)計html代碼大全菜鳥上海關(guān)鍵詞優(yōu)化公司bwyseo
  • 專業(yè)3合1網(wǎng)站建設(shè)知乎推廣渠道