当前位置: 首页 > news >正文

网站关键词有哪些烟台网站建设地址

网站关键词有哪些,烟台网站建设地址,营销网站建设广西,wordpress在哪里下载链表分割_牛客题霸_牛客网现有一链表的头指针 ListNode* pHead#xff0c;给一定值x#xff0c;编写一段代码将所有小于x的。题目来自【牛客题霸】https://www.nowcoder.com/practice/0e27e0b064de4eacac178676ef9c9d70思路: 代码: /* struct ListNode {int val;struct List…链表分割_牛客题霸_牛客网现有一链表的头指针 ListNode* pHead给一定值x编写一段代码将所有小于x的。题目来自【牛客题霸】https://www.nowcoder.com/practice/0e27e0b064de4eacac178676ef9c9d70思路: 代码: /* struct ListNode {int val;struct ListNode *next;ListNode(int x) : val(x), next(NULL) {} };*/ class Partition { public:ListNode* partition(ListNode* pHead, int x) {// write code here//创建两个非空链表:小链表和大链表ListNode* lesstHead,*lesstTail;lesstHead lesstTail (ListNode*)malloc(sizeof(ListNode));ListNode* greaterHead,*greaterTail;greaterHead greaterTail (ListNode*)malloc(sizeof(ListNode));//创建临时变量来遍历原数组ListNode* prev pHead;while(prev){//判断当前节点是否小于xif(prev-val x){//插入到小链表中lesstTail-next prev;lesstTail lesstTail-next;}else{//插入到大链表中greaterTail-next prev;greaterTail greaterTail-next;}prev prev-next;}//退出循环原链表遍历完成//连接两个链表lesstTail-next greaterHead-next;ListNode* ret lesstHead-next;free(lesstHead);lesstHead NULL;free(greaterHead);greaterHead NULL;return ret;} }; 提交结果: 当我们提交代码之后代码有问题,那么代码到底哪里的逻辑不合适呢?我们画图看一下。 /* struct ListNode {int val;struct ListNode *next;ListNode(int x) : val(x), next(NULL) {} };*/ class Partition { public:ListNode* partition(ListNode* pHead, int x) {// write code here//创建两个非空链表:小链表和大链表ListNode* lesstHead,*lesstTail;lesstHead lesstTail (ListNode*)malloc(sizeof(ListNode));ListNode* greaterHead,*greaterTail;greaterHead greaterTail (ListNode*)malloc(sizeof(ListNode));//创建临时变量来遍历原数组ListNode* prev pHead;while(prev){//判断当前节点是否小于xif(prev-val x){//插入到小链表中lesstTail-next prev;lesstTail lesstTail-next;}else{//插入到大链表中greaterTail-next prev;greaterTail greaterTail-next;}prev prev-next;}//将大链表的尾节点的next指针置为NULLgreaterTail-next NULL;//连接两个链表lesstTail-next greaterHead-next;ListNode* ret lesstHead-next;free(lesstHead);lesstHead NULL;free(greaterHead);greaterHead NULL;return ret;} }; 提交结果:
http://www.zqtcl.cn/news/703264/

相关文章:

  • 网站建设具体详细过程WordPress usdt收款
  • 网站标题应怎设置生产备案号怎么查询网站
  • 怎样建立网站目录结构网站 项目方案
  • jsp做网站还响应式科技公司网站模板
  • 杭州网站建设设计公司做阀门网站
  • 用模板建站青岛企业网站制作公司
  • 网站建设经费预算表辽宁工程建设招标网
  • sql数据库查询网站模板谷歌浏览器网页版入口
  • 成都h5建站市场监督管理局举报电话
  • 百度推广弄个网站头像要钱吗?最新新闻热点素材
  • 江苏做网站找谁wordpress主题设置插件
  • 郑州微信网站开发建筑网招工平台
  • 给网站挂黑链普工招聘最新招聘信息
  • 重庆推广网站排名价格上海房产信息网官网
  • 深圳网站公司制作网络公司排名
  • 郑州高端做网站网页制作与网站建设实战大全光盘
  • 科技网站制作公司免费模板建站网站
  • 网页排版精美的中文网站单页设计软件
  • 图书馆网站建设情况会员卡管理系统价格
  • 网站建设的通知沈阳品牌设计公司
  • html5网站框架宝安网站建设深圳信科
  • 做网站单页分销电商平台开发
  • 吉林网站备案南京网站开发选南京乐识好
  • 某网站建设方案纯文本网站连接
  • 怎样做网页游戏网站智通人才网东莞最新招聘信息官网
  • 中英文网站建设wordpress 旅行
  • ic商城网站建设南大资源分享wordpress
  • 永兴集团网站织梦网站模板下载
  • html怎么做网站地图柳州小程序制作公司
  • 微网站自助建站京东自营入驻流程及费用