Files
freeCodeCamp/curriculum/challenges/chinese/10-coding-interview-prep/rosetta-code/balanced-brackets.chinese.md
2020-08-16 04:45:18 +05:30

3.5 KiB

title, id, challengeType, videoUrl, localeTitle
title id challengeType videoUrl localeTitle
Balanced brackets 594dc6c729e5700999302b45 5 平衡括号

Description

确定生成的括号字符串是否平衡;也就是说,它是否完全由成对的开/关括号(按此顺序)组成,其中没有一个错误嵌套。

例子:

(空)是的

[]是的

][

[][]是的

][][

[]][[] false

[[[[]]]]是的

Instructions

Tests

tests:
  - text: <code>isBalanced</code>是一个函数。
    testString: assert(typeof isBalanced === 'function');
  - text: <code>isBalanced(&quot;[]&quot;)</code>应该返回true。
    testString: assert(isBalanced(testCases[0]));
  - text: <code>isBalanced(&quot;]][[[][][][]][&quot;)</code>应该返回false。
    testString: assert(!isBalanced(testCases[1]));
  - text: <code>isBalanced(&quot;[][[[[][][[[]]]]]]&quot;)</code>应该返回true。
    testString: assert(isBalanced(testCases[2]));
  - text: <code>isBalanced(&quot;][&quot;)</code>应该返回true。
    testString: assert(!isBalanced(testCases[3]));
  - text: <code>isBalanced(&quot;[[[]]]][[]&quot;)</code>应该返回true。
    testString: assert(!isBalanced(testCases[4]));
  - text: <code>isBalanced(&quot;][[]&quot;)</code>应该返回true。
    testString: assert(!isBalanced(testCases[5]));
  - text: <code>isBalanced(&quot;][[][]][[[]]&quot;)</code>应该返回true。
    testString: assert(!isBalanced(testCases[6]));
  - text: <code>isBalanced(&quot;[[][]]][&quot;)</code>应该返回true。
    testString: assert(!isBalanced(testCases[7]));
  - text: <code>isBalanced(&quot;[[[]]][[]]]][][[&quot;)</code>应该返回true。
    testString: assert(!isBalanced(testCases[8]));
  - text: <code>isBalanced(&quot;[]][[]]][[[[][]]&quot;)</code>应该返回true。
    testString: assert(!isBalanced(testCases[9]));
  - text: <code>isBalanced(&quot;][]][[][&quot;)</code>应该返回true。
    testString: assert(!isBalanced(testCases[10]));
  - text: <code>isBalanced(&quot;[[]][[][]]&quot;)</code>应该返回true。
    testString: assert(isBalanced(testCases[11]));
  - text: <code>isBalanced(&quot;[[]]&quot;)</code>应该返回true。
    testString: assert(isBalanced(testCases[12]));
  - text: <code>isBalanced(&quot;]][]][[]][[[&quot;)</code>应该返回true。
    testString: assert(!isBalanced(testCases[13]));
  - text: <code>isBalanced(&quot;][]][][[&quot;)</code>应该返回true。
    testString: assert(!isBalanced(testCases[14]));
  - text: <code>isBalanced(&quot;][][&quot;)</code>应该返回true。
    testString: assert(!isBalanced(testCases[15]));
  - text: <code>isBalanced(&quot;[[]]][][][[]][&quot;)</code>应该返回true。
    testString: assert(!isBalanced(testCases[16]));
  - text: <code>isBalanced(&quot;&quot;)</code>应该返回true。
    testString: assert(isBalanced(testCases[17]));

Challenge Seed

function isBalanced (str) {
  // Good luck!
  return true;
}

After Test

console.info('after the test');

Solution

// solution required