# LeetCode: Evaluate The Bracket Pairs Of A String Solution

```.css-ds3kc{display:table-row;}.css-1t8atru{display:table-cell;opacity:0.5;padding-right:var(--chakra-space-6);-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;text-align:right;}1.css-2qghsv{display:table-cell;}/**2 * @param {string} s3 * @param {string[][]} knowledge4 * @return {string}5 */6var evaluate = function (s, knowledge) {7  const dict = knowledge.reduce(8    (acc, el) => acc.set(`(\${el[0]})`, el[1]),9    new Map()10  )11  const N = s.length12  let tokens = []13  let token = ""14  for (let i = 0; i < N; i++) {15    if (s[i] === "(") {16      tokens.push(token)17      token = ""18    }19    token += s[i]20    if (s[i] === ")") {21      tokens.push(token)22      token = ""23    }24  }25  if (token) {26    tokens.push(token)27  }28
29  return tokens30    .filter(Boolean)31    .map(token => (token[0] === "(" ? dict.get(token) || "?" : token))32    .join("")33}```

leetcode

hash table

string

## Next Post

LeetCode: Minimum Number Of Operations To Reinitialize A Permutation

Mar 28, 2021

Search Posts