- 浏览: 174708 次
- 性别:
- 来自: 济南
文章分类
最新评论
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 ...
给定一个链表,将奇数的节点放在前面,将偶数的节点放在后面。代码如下:
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 ...
给定一个链表,将奇数的节点放在前面,将偶数的节点放在后面。代码如下:
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ public class Solution { public ListNode oddEvenList(ListNode head) { if(head == null || head.next == null) return head; ListNode oddNode = head; ListNode evenNode = head.next; ListNode helper = evenNode; while(evenNode != null && evenNode.next != null) { oddNode.next = evenNode.next; evenNode.next = evenNode.next.next; evenNode = evenNode.next; oddNode = oddNode.next; } oddNode.next = helper; return head; } }
发表评论
-
498. Diagonal Traverse
2019-11-15 13:52 229Given a matrix of M x N eleme ... -
496 Next Greater Element I
2019-11-14 13:50 232You are given two arrays (witho ... -
Word Break II
2016-03-09 03:15 348Given a string s and a dictiona ... -
Insert Interval
2016-03-08 02:11 342Given a set of non-overlapping ... -
Merge Intervals
2016-03-07 05:25 461Given a collection of intervals ... -
Merge k Sorted Lists
2016-03-07 04:03 525Merge k sorted linked lists and ... -
Multiply Strings
2016-03-06 07:27 435Given two numbers represented a ... -
N-Queens II
2016-03-06 03:06 624Follow up for N-Queens problem. ... -
N-Queens
2016-03-06 02:47 435The n-queens puzzle is the prob ... -
First Missing Positive
2016-03-05 03:09 392Given an unsorted integer array ... -
Spiral Matrix
2016-03-04 03:39 522Given a matrix of m x n element ... -
Trapping Rain Water
2016-03-04 02:54 542Given n non-negative integers r ... -
Repeated DNA Sequences
2016-03-03 03:10 379All DNA is composed of a series ... -
Increasing Triplet Subsequence
2016-03-02 02:48 870Given an unsorted array return ... -
Maximum Product of Word Lengths
2016-03-02 01:56 885Given a string array words, fin ... -
LRU Cache
2016-02-29 10:37 559Design and implement a data str ... -
Super Ugly Number
2016-02-29 07:07 611Write a program to find the nth ... -
Longest Increasing Path in a Matrix
2016-02-29 05:56 771Given an integer matrix, find t ... -
Coin Change
2016-02-29 04:39 741You are given coins of differen ... -
Minimum Height Trees
2016-02-29 04:11 635For a undirected graph with tre ...
相关推荐
Odd Even Linked List Add Two Numbers Reverse Linked List II Partition List Remove Duplicates from Sorted List Remove Duplicates from Sorted List II Rotate List Remove Nth Node From End of List Swap ...
* [Linked List](https://github.com/kamyu104/LeetCode#linked-list) * [Stack](https://github.com/kamyu104/LeetCode#stack) * [Queue](https://github.com/kamyu104/LeetCode#queue) * [Heap]...
MPI环境下实现的奇偶排序。仅用到基础的Isend,Irecv,send,recv,Bcast等功能。
Digital Design Odd or Even Parity
letter Odd&Even.py
资源分类:Python库 所属语言:Python 资源全名:EvenOrOdd-0.1.5-py3-none-any.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
C语言编程之 奇偶校验 ,采用规范的C语言编程风格,程序通俗易懂。
奇数 解决的问题:知道数组中的每个数字是奇数还是偶数。
使用 Java 进行 TDDing 实践:Oddeven-Kata
用于检查数据的正确性。具体而言,在发送端,通过增加校验位,使有效数据位和校验位组成数据校验码;在接收端,根据接收的数据校验码判断数据的正确性。
Even Odd Number Example
import { whole } from '@aureooms/js-odd-even-mergesort' ; import { list } from '@aureooms/js-itertools' ; import { increasing } from '@aureooms/js-compare' ; import { swap } from '@aureooms/js-array'...
add two numbers in java
代码稍微有点儿缺陷,默认是10个数据,用5个进程进行排序。所以其中的比较函数写死了,大家可以自己重新改一下这里。
奇数偶数识别器,输入一个数据,判断该数据为奇数或偶数。
Odd_Even_Thread
STC8G1K08单片机串口1串口2实现None无校验,Odd奇校验,Even偶校验 程序最大优点是通俗易懂,易移植,多文件编程
这是图像处理中获得奇场矩阵的最基本也最实用的函数,很值得一看。
Finding number even or odd
odd 一个代码比较的小工具,能够集成到vs2010中。