---
# System prepended metadata

title: "24.\_Swap Nodes in Pairs"
tags: [Leetcode, ' Drew']

---

---
title: 
image: 
description: 
tags: Leetcode, Drew
---
# 24. Swap Nodes in Pairs

```graphviz
digraph {
        rankdir="LR";
        node [shape=none];
        edge [arrowhead=vee,headclip=false, tailclip=false]

        p2p[shape=plaintext,fontcolor=red]
        tmp[shape=plaintext,fontcolor=blue]
        
        Head [label=<
            <TABLE BORDER="0" CELLBORDER="1" cellspacing="0">
            <TR>
                  <TD PORT="Val">Head</TD>
                  <TD PORT="Next"> </TD>
              </TR>
            </TABLE>>,rankdir="TB"];
            
        A1 [label=<
            <TABLE BORDER="0" CELLBORDER="1" cellspacing="0">
            <TR>
                  <TD PORT="Val">1</TD>
                  <TD PORT="Next"> </TD>
              </TR>
            </TABLE>>];

        A2 [label=<
            <TABLE BORDER="0" CELLBORDER="1" cellspacing="0">
            <TR>
                  <TD PORT="Val">2</TD>
                  <TD PORT="Next"> </TD>
              </TR>
            </TABLE>>];
            
        A3 [label=<
        <TABLE BORDER="0" CELLBORDER="1" cellspacing="0">
        <TR>
              <TD PORT="Val">3</TD>
              <TD PORT="Next"> </TD>
          </TR>
        </TABLE>>];
        
        A4 [label=<
        <TABLE BORDER="0" CELLBORDER="1" cellspacing="0">
        <TR>
              <TD PORT="Val">4</TD>
              <TD PORT="Next"> </TD>
          </TR>
        </TABLE>>];
        
        
        A1:Next:c -> A2:w;
        A2:Next:c -> A3:w;
        A3:Next:c -> A4:w;
        A4:Next:c -> Nil:w;
        
        {
        node [shape=record];
        edge [arrowhead=vee,headclip=true, tailclip=true]
            rank=same;
            tmp -> A1:c;
            p2p -> Head;
            Head:Next:c -> A1:c;
        }

}
```
---
```graphviz
digraph {
        rankdir="LR";
        node [shape=none];
        edge [arrowhead=vee,headclip=false, tailclip=false]

        p2p[shape=plaintext,fontcolor=red]
        tmp[shape=plaintext,fontcolor=blue]
        
        Head [label=<
            <TABLE BORDER="0" CELLBORDER="1" cellspacing="0">
            <TR>
                  <TD PORT="Val">Head</TD>
                  <TD PORT="Next"> </TD>
              </TR>
            </TABLE>>,rankdir="TB"];
            
        A1 [label=<
            <TABLE BORDER="0" CELLBORDER="1" cellspacing="0">
            <TR>
                  <TD PORT="Val">1</TD>
                  <TD PORT="Next"> </TD>
              </TR>
            </TABLE>>];

        A2 [label=<
            <TABLE BORDER="0" CELLBORDER="1" cellspacing="0">
            <TR>
                  <TD PORT="Val">2</TD>
                  <TD PORT="Next"> </TD>
              </TR>
            </TABLE>>];
            
        A3 [label=<
        <TABLE BORDER="0" CELLBORDER="1" cellspacing="0">
        <TR>
              <TD PORT="Val">3</TD>
              <TD PORT="Next"> </TD>
          </TR>
        </TABLE>>];
        
        A4 [label=<
        <TABLE BORDER="0" CELLBORDER="1" cellspacing="0">
        <TR>
              <TD PORT="Val">4</TD>
              <TD PORT="Next"> </TD>
          </TR>
        </TABLE>>];
        
        tmp -> A1:w;
        A1:Next:c -> A2:w;
        A2:Next:c -> A3:w;
        A3:Next:c -> A4:w;
        A4:Next:c -> Nil:w;
        
        {
        node [shape=record];
        edge [arrowhead=vee,headclip=true, tailclip=true]
            rank=same;
            //tmp -> A1;
            p2p -> Head;
            Head:Next:c -> A2:c;
        }

}
```
---
```graphviz
digraph {
        rankdir="LR";
        node [shape=none];
        edge [arrowhead=vee,headclip=false, tailclip=false]

        p2p[shape=plaintext,fontcolor=red]
        tmp[shape=plaintext,fontcolor=blue]
        
        Head [label=<
            <TABLE BORDER="0" CELLBORDER="1" cellspacing="0">
            <TR>
                  <TD PORT="Val">Head</TD>
                  <TD PORT="Next"> </TD>
              </TR>
            </TABLE>>,rankdir="TB"];
            
        A1 [label=<
            <TABLE BORDER="0" CELLBORDER="1" cellspacing="0">
            <TR>
                  <TD PORT="Val">1</TD>
                  <TD PORT="Next"> </TD>
              </TR>
            </TABLE>>];

        A2 [label=<
            <TABLE BORDER="0" CELLBORDER="1" cellspacing="0">
            <TR>
                  <TD PORT="Val">2</TD>
                  <TD PORT="Next"> </TD>
              </TR>
            </TABLE>>];
            
        A3 [label=<
        <TABLE BORDER="0" CELLBORDER="1" cellspacing="0">
        <TR>
              <TD PORT="Val">3</TD>
              <TD PORT="Next"> </TD>
          </TR>
        </TABLE>>];
        
        A4 [label=<
        <TABLE BORDER="0" CELLBORDER="1" cellspacing="0">
        <TR>
              <TD PORT="Val">4</TD>
              <TD PORT="Next"> </TD>
          </TR>
        </TABLE>>];
        
        tmp -> A1:w;
        A1:Next:c -> A3:w;
        A2:Next:c -> A3:w;
        A3:Next:c -> A4:w;
        A4:Next:c -> Nil:w;
        
        {
        node [shape=record];
        edge [arrowhead=vee,headclip=true, tailclip=true]
            rank=same;
            //tmp -> A1;
            p2p -> Head;
            Head:Next:c -> A2:c;
        }

}
```
---
```graphviz
digraph {
        rankdir="LR";
        node [shape=none];
        edge [arrowhead=vee,headclip=false, tailclip=false]

        p2p[shape=plaintext,fontcolor=red]
        tmp[shape=plaintext,fontcolor=blue]
        
        Head [label=<
            <TABLE BORDER="0" CELLBORDER="1" cellspacing="0">
            <TR>
                  <TD PORT="Val">Head</TD>
                  <TD PORT="Next"> </TD>
              </TR>
            </TABLE>>,rankdir="TB"];
            
        A1 [label=<
            <TABLE BORDER="0" CELLBORDER="1" cellspacing="0">
            <TR>
                  <TD PORT="Val">1</TD>
                  <TD PORT="Next"> </TD>
              </TR>
            </TABLE>>];

        A2 [label=<
            <TABLE BORDER="0" CELLBORDER="1" cellspacing="0">
            <TR>
                  <TD PORT="Val">2</TD>
                  <TD PORT="Next"> </TD>
              </TR>
            </TABLE>>];
            
        A3 [label=<
        <TABLE BORDER="0" CELLBORDER="1" cellspacing="0">
        <TR>
              <TD PORT="Val">3</TD>
              <TD PORT="Next"> </TD>
          </TR>
        </TABLE>>];
        
        A4 [label=<
        <TABLE BORDER="0" CELLBORDER="1" cellspacing="0">
        <TR>
              <TD PORT="Val">4</TD>
              <TD PORT="Next"> </TD>
          </TR>
        </TABLE>>];
        
        tmp -> A1:w;
        A1:Next:c -> A3:w;
        A2:Next:c -> A1:w;
        A3:Next:c -> A4:w;
        A4:Next:c -> Nil:w;
        
        {
        node [shape=record];
        edge [arrowhead=vee,headclip=true, tailclip=true]
            rank=same;
            //tmp -> A1;
            p2p -> Head;
            Head:Next:c -> A2:c;
        }

}
```