Skip to content

Instantly share code, notes, and snippets.

View JamesJi9277's full-sized avatar

Qi Ji JamesJi9277

  • Okta
  • San Francisco, CA
View GitHub Profile
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;