慣性聚合 高效追讀感興趣之博客、新聞、科技資訊
閱原文 以慣性聚合開啟

推薦訂閱源

小众软件
小众软件
博客园 - 叶小钗
有赞技术团队
有赞技术团队
大猫的无限游戏
大猫的无限游戏
博客园_首页
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
L
LangChain Blog
Hugging Face - Blog
Hugging Face - Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
aimingoo的专栏
aimingoo的专栏
Blog — PlanetScale
Blog — PlanetScale
爱范儿
爱范儿
T
Tailwind CSS Blog
Jina AI
Jina AI
量子位
Stack Overflow Blog
Stack Overflow Blog
人人都是产品经理
人人都是产品经理
J
Java Code Geeks
V
Visual Studio Blog
月光博客
月光博客

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python)
栈于技术面试:三问题逐解
Axel Espinos · 2026-05-28 · via DEV Community

初解LeetCode之题,每题若新世界。经时方悟,众题多依结构而群,若能识其式,则题自解。今日论栈。

于其前文已述栈之运作。今以是基,解三古题。

Tres problemas distintos (balanced parentheses, reverse string, simplify path) convergiendo en un mismo stack que los resuelve

所遇之境:

  • 三题逐一解之:平衡括号,逆序字符串,简化路径
  • 堆栈之用,非止面试之场

简要备忘

后进先出:末入者先出。push加于顶上,pop 降顶。于 JavaScript,数组已具栈之能。若求详尽,则在前文 中详述

于此,论其弊。

第一弊:平衡括号

"有效括号"于 LeetCode

弊状:予一串 s,唯含括号而已。()[]{},审其可否。每启必有其合,且序当得宜。

例证
Input:  "()[]{}"   → true
Input:  "([)]"     → false
Input:  "{[]}"     → true

入全景模式 出全屏模式

吾等何以思之?

"后者启者,先者闭之。"此乃栈之长也。

循文而度。每遇启,则入栈;每逢阖,必应栈顶。若终而栈空,则尽合矣。

Paso a paso del stack validando balanced parentheses

解法

function validParentheses(s) {
  const stack = [];
  const pairs = { ")": "(", "}": "{", "]": "[" };

  for (const char of s) {
    if (char === "(" || char === "{" || char === "[") {
      stack.push(char);
    } else if (stack.pop() !== pairs[char]) {
      return false;
    }
  }

  return stack.length === 0;
}

全屏模式 退出全屏模式

要义:

  1. pairs 每阖必配其启。
  2. 启入栈中。阖则验之。pop
  3. 若堆栈为空时pop,返之undefined然较之则谬矣。安闲,如此则无需复检。
  4. 终,栈必空。

繁复:時為O(n),空為O(n)。

第二题:逆序字符串(易)

适变之术也"反转字符串"之LeetCode吾将逆一字,用栈为之。

题曰:予一字符串s,求其逆序字符串。

例证
Input:  "stack"   → "kcats"
Input:  "hello"   → "olleh"

入全屏模式 出全屏模式

吾将何以思之?

"逆"者,入之有序,出之逆序也。此即栈之功用。

于世中,汝将用之s.split("").reverse().join("")吾已备妥。今以栈观其理。

Paso a paso del stack invirtiendo la palabra stack

解也

var reverseString = function (s) {
  const stack = [...s]; // crea un stack con los caracteres
  let reversed = "";

  while (stack.length > 0) {
    reversed += stack.pop();
  }

  return reversed;
};

入全景模式 出全屏模式

吾等悉将诸字符纳于栈中,复逐一取出之。如pop返其末入者,字反而出。

繁复:時O(n)空O(n)。

第三题:简化路径(中)

简化路径(LeetCode)请提供需要翻译的英文文本。

难题:既得Unix之绝对路径,化其为标准形。

规约:

  • .此乃当前目录。
  • ..升一级。
  • //此乃视之如也/.
  • 其果未终也/,惟根不除。
例证
Input:  "/home//foo/"       → "/home/foo"
Input:  "/../"              → "/"
Input:  "/a/./b/../../c/"   → "/c"

入全景模式 出全屏模式

吾等何以思之?

何所为之?..? 乃返于前所之目录。彼处有标,吾辈当记所经之路,方可回溯。

吾辈启程于径。/吾等遍察诸构件。

  • """.",勿视。
  • ".."揭栈顶之极。
  • 凡他物皆为目录,入栈而去。

终,栈含简路之目录。

Paso a paso del stack simplificando una ruta de Unix

解也

var simplifyPath = function (path) {
  const stack = [];

  for (const part of path.split("/")) {
    if (part === "" || part === ".") continue;
    if (part === "..") stack.pop();
    else stack.push(part);
  }

  return "/" + stack.join("/");
};

入全景模式 出全屏模式

谨示:于JavaScript,pop临空栈,无有损焉,惟返undefined耳。是故,若径途欲升越本根,则无需复加验之。

难易:时若O(n),地亦O(n)。

三者之理,其趣何在?

若续读之,当见同此。三者皆解本源之同题,可返归旧境。

  • 平衡括号:记其末启,以验其合。
  • 逆序字符串:返其逆序之序。
  • 简化路径:..返归一阶。

此乃栈之奇能。凡遇难题,嘱汝忆其末,撤其失,或逆序而理,其策几莫不归栈。

栈之用,不止面试

栈非面试之戏言。凡"返"之理,遍现于世:

  • 浏览器之"后退"钮,即栈也。
  • 编辑器之"撤销/重做",亦然。
  • 诸语言之调用栈(是故有栈溢出之误)。
  • 数据之管道,须存所睹之境。

为续习之故

力扣难题之题:

  1. 极小栈,易。
  2. 棒球游戏,易。
  3. 逆波兰表达式求值,中难.
  4. 每日温度,中难。此乃单调栈模式之引言.

何者使君费思最多?请留言告知。吾则觉简化路径题,颇费周折。