* function ListNode(x){
 *   this.val = x;
 *   this.next = null;
 * }
 */

/**
  * 
  * @param head ListNode类 
  * @param x int整型 
  * @return ListNode类
  */
function partition( head , x ){
    let LH = null;
    let LT = null;
    let RH = null;
    let RT = null;
    let a = head;
    while (a != null){
        let next = a.next;
        a.next = null;
        if (a.val < x){
            if (LH == null){
                LH = a;
                LT = a;
            }
            else{
                LT.next = a;
                LT = a;
            }
        }else{
            if (!RH){
                RH = a;
                RT = a;
            }
            else{
                RT.next = a;
                RT = a;
            }
        }
        a = next;
    }
    if (LH){
        LT.next = (RH == null) ? null : RH;
        return LH;
    }else
        return RH;
}
module.exports = {
    partition : partition
};
 * function ListNode(x){
 *   this.val = x;
 *   this.next = null;
 * }
 */

/**
  * 
  * @param head ListNode类 
  * @param x int整型 
  * @return ListNode类
  */
function partition( head ,  x ) {
    if(head == null || head.next == null || x == 0)    return head
    var current = head
    var lowList = {}
    var lowCur = lowList
    var highList = {}
    var highCur = highList
    while(current){
        if(current.val < x){
            lowCur.next = current
            lowCur = lowCur.next
        }else{
            highCur.next = current
            highCur = highCur.next
        }
        current = current.next
    }
    highCur.next = null
    lowCur.next = highList.next
    return lowList.next
}
module.exports = {
    partition : partition
};