This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution{ | |
public int kthtoLast(LinkedListNode head, int k){ | |
if (k < 0|| head == null) | |
return -1; | |
LinkedListNode p1 = head; | |
LinkedListNode p2 = head; | |
//moving p2 to reach the position length - k. | |
for(int i = 0; i< k - 1; i++) | |
{ | |
p2 = p2.next; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution{ | |
public int kthtoLast(LinkedListNode head, int k){ | |
if (k < 0|| head == null) | |
return -1; | |
LinkedListNode p1 = head; | |
LinkedListNode p2 = head; | |
//moving p2 to reach the position length - k. | |
for(int i = 0; i< k - 1; i++) | |
{ | |
p2 = p2.next; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution{ | |
public int kthtoLast(LinkedListNode head, int k){ | |
if (k < 0|| head == null) | |
return -1; | |
LinkedListNode p1 = head; | |
LinkedListNode p2 = head; | |
//moving p2 to reach the position length - k. | |
for(int i = 0; i< k - 1; i++) | |
{ | |
p2 = p2.next; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution{ | |
public int kthtoLast(LinkedListNode head, int k){ | |
if (k < 0|| head == null) | |
return -1; | |
LinkedListNode p1 = head; | |
LinkedListNode p2 = head; | |
//moving p2 to reach the position length - k. | |
for(int i = 0; i< k - 1; i++) | |
{ | |
p2 = p2.next; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution{ | |
public int kthtoLast(LinkedListNode head, int k){ | |
if (k < 0|| head == null) | |
return -1; | |
LinkedListNode p1 = head; | |
LinkedListNode p2 = head; | |
//moving p2 to reach the position length - k. | |
for(int i = 0; i< k - 1; i++) | |
{ | |
p2 = p2.next; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution{ | |
public int kthtoLast(LinkedListNode head, int k){ | |
if (k < 0|| head == null) | |
return -1; | |
LinkedListNode p1 = head; | |
LinkedListNode p2 = head; | |
//moving p2 to reach the position length - k. | |
for(int i = 0; i< k - 1; i++) | |
{ | |
p2 = p2.next; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution{ | |
public int kthtoLast(LinkedListNode head, int k){ | |
if (k < 0|| head == null) | |
return -1; | |
LinkedListNode p1 = head; | |
LinkedListNode p2 = head; | |
//moving p2 to reach the position length - k. | |
for(int i = 0; i< k - 1; i++) | |
{ | |
p2 = p2.next; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution{ | |
public int kthtoLast(LinkedListNode head, int k){ | |
if (k < 0|| head == null) | |
return -1; | |
LinkedListNode p1 = head; | |
LinkedListNode p2 = head; | |
//moving p2 to reach the position length - k. | |
for(int i = 0; i< k - 1; i++) | |
{ | |
p2 = p2.next; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution{ | |
public int kthtoLast(LinkedListNode head, int k){ | |
if (k < 0|| head == null) | |
return -1; | |
LinkedListNode p1 = head; | |
LinkedListNode p2 = head; | |
//moving p2 to reach the position length - k. | |
for(int i = 0; i< k - 1; i++) | |
{ | |
p2 = p2.next; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution{ | |
public int kthtoLast(LinkedListNode head, int k){ | |
if (k < 0|| head == null) | |
return -1; | |
LinkedListNode p1 = head; | |
LinkedListNode p2 = head; | |
//moving p2 to reach the position length - k. | |
for(int i = 0; i< k - 1; i++) | |
{ | |
p2 = p2.next; |