CommonLisp / LeetCode "1614. max nesting depth of the parentheses" 20 Oct 2020 🗓️ 20 Oct, 2020 문제 https://leetcode.com/problems/maximum-nesting-depth-of-the-parentheses/ 작성한 코드 1 2 3 4 5 6 7 8 (defun max-nested-parentheses (s) (declare (optimize (speed 3) (safety 0)) (type simple-string s)) (loop with n fixnum = 0 for ch across s when (member ch '(#\( #\))) do (incf n (if (eql #\( ch) 1 -1)) maximizing n)) 코드 의도 우아한 코드보다는 공간복잡도가 O(1) 이고 싶었다. Edit SBCL에 맞춰 코드에 타입을 지정해줘봤다. 결과 어셈블리 코드가 조금 짧아졌다. #leet-code #lisp