328. Odd Even Linked List

HDRP shader 获取阴影(Custom Pass) Unity:2021.3.0f1 HDRP:12.1.6 阅读详情

Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes.

You should try to do it in place. The program should run in O(1) space complexity and O(nodes) time complexity.

Example:
Given 1->2->3->4->5->NULL,
return 1->3->5->2->4->NULL.

Note:
The relative order inside both the even and odd groups should remain as it was in the input. 
The first node is considered odd, the second node even and so on ...


这道题坑得很,他说的是链表元素是第几个这种序号,我愣是没看懂。第一个奇数,第二个偶数,第三个奇数,等等。

不说了代码如下,注意判空就行了。

通常在while循环中判断链表某个值是否不能为空,只需看等式右侧就行了。如下面,等是右侧有对even,even->next 的访问,所以它们绝对不能为空。

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode* oddEvenList(ListNode* head) {
        if(head == NULL)
            return NULL;
        
        ListNode* odd = head;
        ListNode* even = head->next;
        ListNode* even_head = even;
        
        while(even && even->next != NULL){
            odd->next = even->next;
            even->next = even->next->next;
            even = even->next;
            odd = odd->next;
        }
        odd->next = even_head;
        
        return head;
    }
};
大数据在电力行业的应用案例解析 -【电力技术】(十)电力数字化运营与大数据精准服务体系建设 电力数字化运营,是大数据在电力行业从技术场景走向业务价值的最终落点。它以数据为纽带,将用户、设备、服务、收益、风险全部纳入统一闭环,实现从 “管好电” 向 “运营好能源资产” 升级。在新型电力系统与市场化改革双重驱动下,谁能用好数据、建好闭环、做好运营,谁就能在服务、成本、效益、安全上建立长期优势。 阅读详情

相关推荐

AIOps智能运维:从数据治理到故障自愈的实践指南

AIOps(智能运维)通过融合人工智能与运维管理,构建了感知-决策-执行的闭环体系。其核心技术包括多维度数据采集、机器学习算法和自动化执行,显著提升了告警治理、故障定位和容量预测的效率。在数据层,全量性、实时性的数据采集是基础,而算法层的异常检测和根因分析则依赖统计方法、孤立森林和LSTM等模型。AIOps尤其适用于处理告警风暴和复杂系统故障,如在电商大促中通过K-Means聚类减少92%的告警量。随着云原生和边缘计算的普及,AIOps正逐步实现与Service Mesh、Serverless等技术的深度集

weixin_30175731的博客 298

328. Odd Even Linked List 题解

328. Odd Even Linked List  题解 题目描述:             Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node numbe

yijingzhi的博客 327

AD9176 双通道高速DAC调试记录

AD9176是一款高性能双通道16位数模转换器,支持高达12.6GSPS采样率,专为多频段无线应用设计。该器件集成8通道15.4Gbps JESD204B接口,支持复数/实数数据输入,每通道最大输入速率达3.08GSPS。关键特性包括:48位高精度NCO、灵活的插值滤波器(最高12倍)、优异的动态性能(SFDR达-83dBc@1.84GHz)以及多芯片同步功能。硬件调试需重点关注时钟配置(建议250M基准时钟)、JESD参数匹配及交流耦合设计。测试指标要求SFDR>55dBc@312MHz,实测值可达65d

universaldata的博客 1511

【LEETCODE】328- Odd Even Linked List [Python]

Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes. You should try to do it in p

aliceyangxi1987的博客 1825

CAPL编程的催化剂——CAPLdll的实现

CANoe作为一款功能强大的总线开发及测试工具,不仅仅是因为其丰富的库函数,最重要的是其兼容了多种编程语言,可以实现灵活的开发,极大的解决了纯CAPL编程所带来的限制,如通过动态链接库(DLL)来实现复杂函数的编写,使其能够在CAPL中可以调用,下面将对DLL的实现进行分析。capldll.cpp这个文件初看相当复杂,从整体上来说,这段代码主要包含了两部分:自定义函数实现和回调函数定义,今天的主要任务是实现自定义函数,这里的函数定义与普通函数定义差不多,只是利用了CAPL的格式。在VS2017工程中打开。

车载控制器AutoSAR软件开发工程师 4662

数字电路逻辑与设计实验三 译码器和数据选择器

1. 译码器功能测试 将 74LS139 按图 3.1 接线,按表 3.2 输入电平分别置位,填输出状态表。 2. 译码器转换 将双 2-4 线译码器转换为 3-8 线译码器。 (1)画出转换电路图。 (2)在实验箱上接线并验证设计是否正确。 (3)设计并填表写该 3-8 线译码器功能表,画出输入、输出波形。 3. 数据选择器的测试及应用 (1) 将双 4 选 1 数据选择器 74LS153 参照图 3.2 接线,测试其功能并填写功能表 3.3。 (2)将实验箱脉冲信号源中固定连续脉冲 4 个不

欢迎交流学习心得 3097

LeetCode 328. Odd Even Linked List(Medium)

查阅更多的题解,请点击 Problem 328. Odd Even Linked List(Medium) Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not...

彼得.攀的blog 260

Ubuntu零基础入门到精通【1.2讲】:Ubuntu 与 Linux 的关系 —— 你用的到底是什么?

🏆 本文收录于 《滚雪球学 Ubuntu》 专栏。 本专栏面向有一定计算机基础,但尚未系统学习 Linux / Ubuntu 的读者,采用“滚雪球式学习法”:先装好、再会用、再理解、再优化、再实战,带你从第一次进入 Ubuntu 桌面 / 终端开始,逐步掌握 Ubuntu 的日常使用、命令操作、软件安装、系统配置、开发环境搭建与服务器部署能力。

**My Coding Family** 3557

<LeetCode OJ> 328. Odd Even Linked List

328. Odd Even Linked List My Submissions Question Total Accepted: 9271 Total Submissions: 24497 Difficulty: Easy Given a singly linked list, group all odd nodes together followed b

EbowTang的练习场 1953

Ceph入门到精通-存储桶通知

这 通知还可以根据前缀的匹配项过滤掉事件,并且 (1) 键的后缀,(2) 附加到对象的元数据属性, 或 (3) 对象标签。在此模式下,操作仅在以下之后确认(确认) 通知将发送到主题的已配置终端节点。这意味着 通知的往返时间(发送 通知主题的终端节点以及接收 确认)被添加到操作本身的延迟中。要更新主题,请使用用于创建主题的相同命令(但在 更新时,使用现有主题的名称和不同的终端节点值)。端口:对于未加密的连接,默认为 5672,对于未加密的连接,默认为 5671 SSL 加密连接。(默认情况下,这是“假的”。

隔壁老瓦的专栏 1134

研制过程评审活动(三)工程研制阶段

工程研制阶段主要任务、及评审活动

Abel的博客 2393

Leetcode 328 Odd Even Linked List

Leetcode 328 Odd Even Linked List Odd Even partition public class Solution { public ListNode oddEvenList(ListNode head) { if (head == null) return null; ListNode odd = head, even =...

weixin_43876597的博客 211

【计算机视觉 | 目标检测】目标检测常用数据集及其介绍(十一)

【计算机视觉 | 目标检测】目标检测常用数据集及其介绍(十一)

wzk4869的博客 749

leetcode 328 Odd Even Linked List C++

这道题把奇数的拿出来,再把偶数的拿出来,连接上即可。 ListNode* oddEvenList(ListNode* head) { if (!head) return head; ListNode *odd = head; ListNode *even = head -> next; ListNode *

wcxdell的专栏 734

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

328 Odd Even Linked List

1 题目 Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes. You should try to do i...

weixin_39145266的博客 122

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

328. Odd Even Linked List**

328. Odd Even Linked List** Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes. Y...

珍妮的选择的博客 251

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

LeetCode 328. Odd Even Linked List

Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes. You should try to do it in

ncst 396

328. Odd Even Linked List #Medium

leetcode 328. Odd Even Linked List #Medium 题意:给定一个有n个节点的单链表,调整节点位置,使原奇数位置节点在偶数位置节点之前,奇(偶)数节点之间相对位置不变, Example: Given 1->2->3->4->5->NULL, return 1->3->5->2->4->NULL. 要求:空间复杂度O(1),时间复杂度O(n) 分析:

coding 418

LeetCode C++ 328. Odd Even Linked List【Linked List】中等

Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes. You should try to do it in place. The program should run in O(1) space complexity and

memcpy0的博客 370

LeetCode 328: Odd Even Linked List

328. Odd Even Linked ListDifficulty: Medium Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value

Cycle1413的博客 544

LeetCode-328. Odd Even Linked List [C++][Java]

Given theheadof a singly linked list, group all the nodes with odd indices together followed by the nodes with even indices, and returnthe reordered list. Thefirstnode is consideredodd, and thesecondnode iseven, and so on.

贫道绝缘子的博客 820
上一篇: 453. Minimum Moves to Equal Array Elements
下一篇: 辗转相除法、埃拉托色尼筛选法、牛顿迭代法证明与C++实现
FreeeLinux
博客等级 码龄11年 421粉丝 356原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址