From c4de753d6db1548205de14efdb4fc9194d7223c4 Mon Sep 17 00:00:00 2001 From: phoenix Date: Sat, 29 May 2021 08:07:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=200020.=E6=9C=89=E6=95=88?= =?UTF-8?q?=E7=9A=84=E6=8B=AC=E5=8F=B7=20Ruby=20=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0015.三数之和.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/problems/0015.三数之和.md b/problems/0015.三数之和.md index 811fc316..4f4ec63a 100644 --- a/problems/0015.三数之和.md +++ b/problems/0015.三数之和.md @@ -336,6 +336,23 @@ var threeSum = function(nums) { ``` +ruby: +```ruby +def is_valid(strs) + symbol_map = {')' => '(', '}' => '{', ']' => '['} + stack = [] + strs.size.times {|i| + c = strs[i] + if symbol_map.has_key?(c) + top_e = stack.shift + return false if symbol_map[c] != top_e + else + stack.unshift(c) + end + } + stack.empty? +end +``` ----------------------- * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)