1, title: Please implement a function to replace each space in string s with “%20”.

Example 1:

Enter: s = “We are happy.”

Output: “We % 20 are % 20 happy.”

Answer key:
Function replaceSpace(s){// Create a new string const res = "for(let I =0; i<s.length; i++){ let str = s[i] if(str === ' '){ res += '%20' }else{ res += str } } return res }Copy the code
2. Title: [Print the linked list from end to end]

Enter the head node of a linked list and return the value of each node from end to end (as an array).

Example 1:

Input: head = [1,3,2] output: [2,3,1]Copy the code
Answer key:
function revercePrint(head){ let res = []; let node = head; while(node ! == null){ res.unshift(node.val); node = node.next } return res }Copy the code