• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
 






Sunshineboy1

 
 

Powered by 博客园
博客园 | 首页 | 新随笔 | 联系 | 订阅 订阅 | 管理
上一页 1 2 3 4 5

2020年7月16日

leetcode-24-Swap Nodes in Pairs
摘要: 思路: 1、由于head 节点可能产生变化,所以创建一个虚拟的头指针 dummy 2.p=dummy,a=p->next,b=p->next->next 3.交换 p->next=b; a->next=b->next; b->next=a; p=a; 代码: /** * Definition for 阅读全文
posted @ 2020-07-16 14:52 Sunshineboy1 阅读(117) 评论(0) 推荐(0)
 
leetcode-61-Remove Nth Node From End of List
摘要: 思路: 先让first指针移动n个节点,只要first->next!=null first&second 同时移动,知道first->next==null 让second->next=second->next->next,就实现删除节点操作 代码: /** * Definition for sing 阅读全文
posted @ 2020-07-16 14:32 Sunshineboy1 阅读(95) 评论(0) 推荐(0)
 
leetcode-61-remove rotate list
摘要: 思路: 双指针法 1、判断链表是否为null 2.获取链表长度--遍历链表 3.向然first指针移动K个位置 4.只要first->next!=null 让second &first指针同时移动,直到first->next==null 5.将链表首尾相连--first->next=head 得到新 阅读全文
posted @ 2020-07-16 14:15 Sunshineboy1 阅读(77) 评论(0) 推荐(0)
 
leetcode-82-remove duplicates from sorted list
摘要: 思路: 1、将链表中head指针移动进行元素的删除,总共有两种情况 a.head->next->val==head->val 直接将head->next 移动到head->next->next 查找出所有相同的元素的区段 b.head->next->val !=head->val 将head 移动到 阅读全文
posted @ 2020-07-16 11:21 Sunshineboy1 阅读(87) 评论(0) 推荐(0)
 

2020年7月14日

leetcode-83-remove duplicates from sorted list
摘要: 思路: 1.判断链表中元素 2.利用双指针遍历链表 3.如果链表中存在pre->val==crur->val >判断cur->next==NULL, prev->next==NULL >cur->next!=NULL prev->next=cur->next 4.如果链表中不存在pre->val== 阅读全文
posted @ 2020-07-14 21:35 Sunshineboy1 阅读(67) 评论(0) 推荐(0)
 
leetcode-86-partition list
摘要: 思路: 1.创建两个空链表 2.遍历原始链表 3.将大于x的node中的val放入到maxlist,将小于node的放入到minlist中 4.将两个链表拼接在一起 /** * Definition for singly-linked list. * struct ListNode { * int  阅读全文
posted @ 2020-07-14 20:11 Sunshineboy1 阅读(103) 评论(0) 推荐(0)
 
leetcode-92-reverse linked list||
摘要: 思路: 1.创建新链表读取不需要反转的node prev=prev->next 2.指针到达反转位置后对该区域进行直接反转 for(int i=m;i<n;i++) { prev->next=cur->next; cur->next=head2->next; head2->next=cur; cur 阅读全文
posted @ 2020-07-14 19:27 Sunshineboy1 阅读(124) 评论(0) 推荐(0)
 

2020年7月13日

listnode-2-two sum
摘要: 思路: 方法一: 1、创建一个新链表用于存放结果 listnode* head=new listnode(-1) 2、需要对进位进行判断 bool carry=false 3、对两个链表是否为空进行判断 4、只要有一个链表不为空,直接对应指针的val相加 5、判断是否有进位,carry=sum>=1 阅读全文
posted @ 2020-07-13 20:02 Sunshineboy1 阅读(205) 评论(0) 推荐(0)
 
leetcode-31-next permutation
摘要: 解题思路: 为了实现找到一个更大的排列 1、首先i从数组end位置向start位置遍历 找到nums[i]>nums[I-1] 跳出循环 2、如果i==0,还没有跳出循环,说明数组本身是按照降序排序,此时应该输出升序,(升序可以使用双指针法完成) 3、如果在i!=0时能够找到nums[i]>nums 阅读全文
posted @ 2020-07-13 15:02 Sunshineboy1 阅读(92) 评论(0) 推荐(0)
 
双指针法
摘要: 解题思路1、指针初始化2、start指针和end指针同时指向首位数3、判断数组中的元素个数4、end指针移动,计算移动后sum5、判断sum是否大于s,如果大于输出ans,同时start指针移动到下一位,6、遍历完成后输出结果 代码 class Solution {public: int minSu 阅读全文
posted @ 2020-07-13 12:23 Sunshineboy1 阅读(99) 评论(0) 推荐(0)
 
上一页 1 2 3 4 5