var minMoves2 = function(nums) {
nums.sort((a,b)=>a-b)
let m=0,res=0
if(nums.length
m=nums[Math.floor(nums.length/2)]
}else{
m=Math.floor((nums[nums.length/2-1]+nums[nums.length/2])/2)
}
for(let i of nums){
res+=Math.abs(i-m)
}
return res
};
var rotateRight = function(head, k) {
if(k===0 || !head ||!head.next){
return head
}
let n=1
let cur=head
while(cur.next){
cur=cur.next
n++
}
cur.next=head
for(let i=0
cur=cur.next
}
let res=cur.next
cur.next=null
return res
}
var deleteDuplicates = function(head) {
let vhead=new ListNode(0,head)
let cur=vhead
while(cur.next && cur.next.next){
if(cur.next.val===cur.next.next.val){
let x=cur.next.val
while(cur.next && cur.next.val===x){
cur.next=cur.next.next
}
}else{
cur=cur.next
}
}
return vhead.next
}
var partition = function(head, x) {
let small=new ListNode(0)
let sHead=small
let large=new ListNode(0)
let lHead=large
let cur=head
while(cur!==null){
if(cur.val<x){
small.next=cur
small=small.next
}else{
large.next=cur
large=large.next
}
cur=cur.next
}
large.next=null
small.next=lHead.next
return sHead.next
}