Re: [LeetCode] 刷到面試 Grind169 C++

看板Marginalman作者 (彗星雷達)時間2年前 (2023/03/08 11:31), 2年前編輯推噓1(101)
留言2則, 2人參與, 2年前最新討論串2/14 (看更多)
Valid Parentheses easy題 幹 寫了這題我才發現我不會用stack 以前作業全都用vector+雙迴圈寫 我好可悲 class Solution { public: bool isValid(string s) { stack<char> st; for(int i =0; i<s.length(); i++){ char c = s[i]; if(c == '(' or c == '[' or c == '{'){ st.push(c); }else{ if(st.empty()){ return false; } if(c == ')' and st.top() == '(' or c == ']' and st.top() == '[' or c == '}' and st.top() == '{' ){ st.pop(); }else{ return false; } } } if(st.empty()){ return true; } return false; } }; -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.113.144.184 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1678246265.A.B96.html

03/08 11:49, 2年前 , 1F
為啥你的題目名稱跟你寫的東西不一樣
03/08 11:49, 1F

03/08 12:13, 2年前 , 2F
靠邀 那是下一題 我耍白痴
03/08 12:13, 2F
※ 編輯: SuiseiLeda (140.113.144.184 臺灣), 03/08/2023 12:14:08
文章代碼(AID): #1a205vkM (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1a205vkM (Marginalman)