一、手写算法


https://leetcode-cn.com/problems/swap-nodes-in-pairs/

思路

  • 借助另外一个链表,进行两两交换

    代码

    ```javascript /**
    • Definition for singly-linked list.
    • function ListNode(val, next) {
    • this.val = (val===undefined ? 0 : val)
    • this.next = (next===undefined ? null : next)
    • } / /*
    • @param {ListNode} head
    • @return {ListNode} */ var swapPairs = function(head) { var newNode = new ListNode(0); newNode.next = head var temp = newNode; while(temp.next !== null && temp.next.next !== null){
      1. var node1 = temp.next;
      2. var node2 = temp.next.next;
      3. temp.next = node2;
      4. node1.next = node2.next;
      5. node2.next = node1;
      6. temp = node1;
      } return newNode.next; };
<a name="fbzED"></a>
### 复杂度分析

- 时间复杂度:O(N)
- 空间复杂度:O(N)

<a name="Ghcnm"></a>
## 二、编程题
```javascript
2.手写题:https://bigfrontend.dev/zh/problem/implement-your-own-Object-create
/**
 * @param {any} proto
 * @return {object}
 */
function myObjectCreate(proto) {
  // your code here
  if(typeof proto !== 'object' && typeof proto !== 'function'){
    throw Error(typeof proto)
  }else if (proto === null) {
     throw Error('null')
  }

  function F(){};
  F.prototype = proto;

  return new F();
}