手写算法:链表的中间结点

876. 链表的中间结点open in new window

思路

用快慢指针,当快走完的时候,慢刚好走到中间

/**
 * @param {ListNode} head
 * @return {ListNode}
 */
var middleNode = function(head) {
  let slow = (fast = head);

  while (fast && fast.next) {
    slow = slow.next;
    fast = fast.next.next;
  }
  return slow;
};

手写题: 简单实现双向绑定 Two-way binding

154. 简单实现双向绑定 Two-way bindingopen in new window

function model(state, element) {
  element.value = state.value;
  Object.defineProperty(state, 'value', {
    get: () => element.value,
    set: newValue => (element.value = newValue)
  });
}
Last Updated:
Contributors: kk