softnshare / kata

Code Kata 這個概念是由 The Pragmatic Programmer 的作者之一Dave Thomas提出的, 想要提升自己的coding skill嗎? 歡迎加入這個slack channel, 加入請參考右邊網頁說明
https://softnshare.wordpress.com/slack/kata/
38 stars 4 forks source link

Valid Braces #16

Open vicky-sunshine opened 8 years ago

vicky-sunshine commented 8 years ago

題目網址:http://www.codewars.com/kata/5277c8a221e209d3f6000b56 敘述: Write a function called validBraces that takes a string of braces, and determines if the order of the braces is valid. validBraces should return true if the string is valid, and false if it's invalid.

This Kata is similar to the Valid Parentheses Kata, but introduces four new characters. Open and closed brackets, and open and closed curly braces. Thanks to @arnedag for the idea!

All input strings will be nonempty, and will only consist of open parentheses '(' , closed parentheses ')', open brackets '[', closed brackets ']', open curly braces '{' and closed curly braces '}'.

What is considered Valid? A string of braces is considered valid if all braces are matched with the correct brace. For example: '(){}[]' and '([{}])' would be considered valid, while '(}', '[(])', and '[({})](]' would be considered invalid.

Examples: validBraces( "(){}[]" ) => returns true validBraces( "(}" ) => returns false validBraces( "[(])" ) => returns false validBraces( "([{}])" ) => returns true

翻譯: 寫個函式來測試輸入字串中括號的順序是不是合法的,如果輸入的字串是合法的就回傳 true,否則回傳 false。 所有的測資都是 nonempty,總共會有六種括號(三種配對) open parentheses ( , closed parentheses ), open brackets [, closed brackets ], open curly braces { and closed curly braces },必須要確定括號們都照順序配對完成,算是合法。

validBraces( "(){}[]" ) => returns true validBraces( "(}" ) => returns false (沒有配對完成 validBraces( "[(])" ) => returns false (沒有照順序被配對到 validBraces( "([{}])" ) => returns true

d2207197 commented 8 years ago

Pass

vampireneo commented 8 years ago

PASS

houjunchen commented 8 years ago

Pass

bucker commented 8 years ago

Pass

vicky-sunshine commented 8 years ago

PASS