Program to x Split linked list for benchmark , Make all less than x The number of nodes is greater than or equal to x Before the node of . If the linked list contains x,x Only need to appear in less than x
After the element of ( As shown below ). Split element x Just be in “ Right half ” that will do , It doesn't need to be placed between the left and right parts .

Examples :

input : head = 3->5->8->5->10->2->1, x = 5
output : 3->1->2->10->5->5->8

A separation , Then connect them .
/** * Definition for singly-linked list. * type ListNode struct { * Val int *
Next *ListNode * } */ func partition(head *ListNode, x int) *ListNode { if head
== nil{ return nil } dummnyhead1,dummnyhead2 :=
&ListNode{-1,nil},&ListNode{-1,nil} cur1,cur2 := dummnyhead1,dummnyhead2 cur :=
head for cur != nil{ if cur.Val <x{ cur1.Next = cur cur = cur.Next cur1 =
cur1.Next }else if cur.Val >=x{ cur2.Next = cur cur = cur.Next cur2 = cur2.Next
} } cur2.Next = nil cur1.Next = dummnyhead2.Next return dummnyhead1.Next }
Give two integers represented by linked list , Each node contains one digit .

These digits are stored in reverse , That is, a bit in the head of the list .

Write a function to sum these two integers , And return the result in the form of linked list .

 

Examples :

input :(7 -> 1 -> 6) + (5 -> 9 -> 2), Namely 617 + 295
output :2 -> 1 -> 9, Namely 912
Advanced : Let's assume that these bits are stored in a positive direction , Please do it again .

Examples :

input :(6 -> 1 -> 7) + (2 -> 9 -> 5), Namely 617 + 295
output :9 -> 1 -> 2, Namely 912

It can simulate the vertical calculation .
/** * Definition for singly-linked list. * type ListNode struct { * Val int *
Next *ListNode * } */ func addTwoNumbers(l1 *ListNode, l2 *ListNode) *ListNode
{ up:=0; ans:= &ListNode{-1,nil}; temp:=ans; for l1!=nil || l2!=nil{ a,b:=0,0;
if(l1!=nil){ a=l1.Val; } if(l2!=nil){ b=l2.Val; }
temp.Next=&ListNode{(a+b+up)%10,nil}; up=int((a+b+up)/10); temp=temp.Next;
if(l1!=nil){ l1=l1.Next; } if(l2!=nil){ l2=l2.Next; } } if(up!=0){
temp.Next=&ListNode{up,nil}; } return ans.Next; }
Write a function , Check whether the input linked list is palindrome .

 

Examples 1:

input : 1->2
output : false 
Examples 2:

input : 1->2->2->1
output : true 

In fact, the optimal solution should be reversed half in place , And then reverse it , My question is to connect go List of .
/** * Definition for singly-linked list. * type ListNode struct { * Val int *
Next *ListNode * } */ func isPalindrome(head *ListNode) bool { s:=make([]int,0)
for head!=nil{ s= append(s, head.Val) head=head.Next } for i:=0;i<
len(s)/2;i++{ if s[i]!=s[len(s)-1-i]{ return false } } return true }

Give two ( one-way ) Linked list , Determine if they intersect and return to the intersection . Note that the definition of the intersection is based on the reference of the node , It's not based on node values . let me put it another way , If a linked list of k Node and another linked list j Nodes are the same node ( The references are identical ), Then the two linked lists intersect .

Examples 1:

input :intersectVal = 8, listA = [4,1,8,4,5], listB = [5,0,1,8,4,5], skipA = 2,
skipB = 3
output :Reference of the node with value = 8
Input explanation : The value of the intersection node is 8 ( be careful , Cannot be if two lists intersect 0). Starting from the respective header , Linked list A by [4,1,8,4,5], Linked list B by
[5,0,1,8,4,5]. stay A in , There are 2 Nodes ; stay B in , There are 3 Nodes .

thinking : Adjust it to the same length , See if you can go to the same node .
/** * Definition for singly-linked list. * type ListNode struct { * Val int *
Next *ListNode * } */ func getIntersectionNode(headA, headB *ListNode)
*ListNode { a,b:=0,0; for temp:=headA;temp!=nil;temp=temp.Next{ a++; } for
temp:=headB;temp!=nil;temp=temp.Next{ b++; } if(a>b){ for i:=a-b;i>0;i--{
headA=headA.Next; } }else if(a<b){ for i:=b-a;i>0;i--{ headB=headB.Next; } }
for headA!=nil && headB!=nil{ if(headA==headB){ return headA; }
headA=headA.Next; headB=headB.Next; } return nil; }
 

Technology
©2019-2020 Toolsou All rights reserved,
( Essence )2020 year 7 month 13 day Wechat applet Inter communication page mysql Modify primary key Thoughts on multi tenant system ( Essence )2020 year 8 month 13 day C# Basic knowledge windform Realize two color sphere Summary of artificial intelligence algorithm python primitive -- lock Lock( Essence )2020 year 7 month 15 day Wechat applet template Use of org.postgresql.util.PSQLException Processing records ( Essence )2020 year 6 month 26 day C# Class library Enum( Extension method )el-ui:select Get value