LeetCode刷题笔录Valid Parentheses

【dify】 dify环境变量配置说明 SMTP_SERVER、SMTP_PORT、SMTP_USERNAME、SMTP_PASSWORD、SMTP_USE_TLS、SMTP_OPPORTUNISTIC_TLS:当 MAIL_TYPE 为 smtp 时,SMTP服务器的相关配置。UPLOAD_IMAGE_FILE_SIZE_LIMIT、UPLOAD_VIDEO_FILE_SIZE_LIMIT、UPLOAD_AUDIO_FILE_SIZE_LIMIT:分别为上传图像、视频、音频文件的大小限制(MB)。 阅读详情

Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.

The brackets must close in the correct order, "()" and "()[]{}" are all valid but "(]" and "([)]" are not.

这题只要求括号是合法的。用一个stack,遇到左括号就丢到stack里,遇到右括号就弹出stack顶上的括号,看看是不是一对。是的话就继续,不是的话返回false。扫描完一遍以后,stack如果不是空的,说明左括号多了,返回false。

public class Solution {
    public boolean isValid(String s) {
        //this stack stores all the left parentheses
        Stack<Character> stack = new Stack<Character>();
        for(int i = 0; i < s.length(); i++){
            char current = s.charAt(i);
            //if the next character is a right par
            if(isLeft(current) == false){
                if(stack.isEmpty()){
                    return false;
                }
                //check the top par on the stack if it formsa pair with the current par
                char top = stack.pop();
                if(isPair(top, current) == false){
                    return false;
                }
            }
            //if the next character is a left par, push onto the stack
            else{
                stack.push(current);
            }
        }
        if(stack.isEmpty() == false)
            return false;
        return true;
        
    }
    
    public boolean isLeft(char c){
        if(c == '[' || c == '{' || c == '(')
            return true;
        else
            return false;
    }
    
    public boolean isPair(char left, char right){
        if(left == '(' && right == ')')
            return true;
        if(left == '[' && right == ']')
            return true;
        if(left == '{' && right == '}')
            return true;
        return false;
    }
}


【OpenClaw从入门到精通】第02篇:5分钟速通!阿里云/华为云一键部署OpenClaw(附避坑指南·2026实测版) 本文聚焦OpenClaw的云端部署场景,针对本地部署“关机即离线、跨设备访问难”的痛点,详解阿里云(主推)和华为云(备选)的一键部署流程。2026实测验证:阿里云轻量应用服务器通过官方OpenClaw镜像可5分钟完成部署,华为云Flexus L实例需补充SSH配置步骤;文中拆解云端部署核心概念(地域选择、端口放行、成本构成),通过“AI助理定时抓取行业资讯并推送钉钉”的虚拟案例演示云端7×24小时运行价值,同时提供模型调用、服务器成本的精细化控制方案,梳理端口访问失败、API-Key权限异常等高频坑点的解决 阅读详情

相关推荐

基于深度强化学习技术优化无线网络中的资源分配(一)DQN部分代码

这是一个GitHub上的开源项目,链接:https://github.com/alexis-anzaldo/Deep-Reinforcement-Learning-for-resource-allocation-in-wireless-networks该项目旨在通过深度强化学习DQL技术优化无线网络中的资源分配,特别关注小型蜂窝和超密集无线蜂窝网络中的功率控制问题,主要目标是提高DRL模型的学习效率和网络吞吐量。

m0_46292040的博客 1537

LeetCode刷题笔录Longest Valid Parentheses

Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring. For "(()", the longest valid parentheses substring is "()",

likecool21的专栏 789

BEVFusion实战:从零搭建LiDAR-Camera融合的3D目标检测环境(附避坑指南)

本文提供了BEVFusion实战指南,详细讲解如何从零搭建LiDAR-Camera融合的3D目标检测环境。内容涵盖环境配置、数据预处理、模型训练与性能优化等关键步骤,并附有实用的避坑技巧,帮助开发者高效部署这一先进的BEV感知算法。

p4q5r6s7t的博客 514

LeetCode刷题笔录 Longest Substring Without Repeating Characters

Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. Fo

likecool21的专栏 1万+

短信验证码逻辑漏洞学习——各种绕过姿势技巧

短信验证码逻辑漏洞学习——各种绕过姿势技巧

记录并分享学习安全的知识点.. 2556

Python爬虫实战:逆向解析天猫商品详情API,精准捕获规格、SKU与促销活动

及浏览器开发者工具),绕过前端渲染的复杂性,直接逆向分析并调用其内部数据接口,从而高效、稳定地抓取商品的关键信息,包括商品规格、多维度SKU信息以及复杂的促销活动。print(f"SKU ID: {sku.sku_id}, 价格: ¥{sku.price}, 库存: {sku.stock}, 规格: {sku.props}")当你访问一个商品链接时,浏览器首先会加载一个几乎为空的HTML骨架,然后通过执行大量的JavaScript代码,向后台服务器发起多个异步请求,最终将获取到的数据填充到页面中。

2201_76125261的博客 1129

LeetCode刷题笔录 Two Sum

Two Sum Given an array of integers, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbers such that they add up to the

likecool21的专栏 1万+

【C++】开源:ncurses终端TUI文本界面库

ncurses配置使用(TUI)

DevFrank的博客 3167

LeetCode刷题笔录 Validate Binary Search Tree

Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node's key.Th

likecool21的专栏 6928

白鲸优化算法(BWO)详解:从生物灵感 to 工程实践

白鲸优化算法(BWO)是一种新型的群体智能优化算法,模拟白鲸的游泳、捕食和鲸落行为。该算法通过平衡因子控制探索与开发阶段的转换:探索阶段采用正弦/余弦函数模拟白鲸的同步游泳,开发阶段引入莱维飞行增强局部搜索,鲸落阶段通过随机更新避免局部最优。BWO具有参数少、实现简单、收敛速度快等优点,已在多个优化问题上展现出优异性能。其数学模型将白鲸的三种核心行为抽象为位置更新公式,实现了全局搜索与局部开发的自然平衡。

qq_42212808的博客 290

【目标检测】基于yolov5的铝型材表面缺陷检测(附代码和数据集,Ubuntu或者Linux系统均可运行)

【目标检测】基于yolov5的铝型材表面缺陷检测(附代码和数据集,Ubuntu或者Linux系统均可运行)

学无止境、积少成多、厚积薄发 2170

Stanford Algorithms学习:Clustering 2

这是紧接上面的一道题,比较有趣 Question 2 In this question your task is again to run the clustering algorithm from lecture, but on a MUCH bigger graph. So big, in fact, that the distances (i.e., edge costs

likecool21的专栏 2567

YOLOv8改进策略【Neck】| CVPR 2024 MFM(Modulation Fusion Module,调制融合模块):动态特征加权融合,突出关键特征抑制冗余

本文主要利用DCMPNet中的 MFM 模块优化 YOLOv8 的目标检测网络模型。模块通过动态调制特征融合过程,实现了对多尺度、跨层级特征的智能聚合。将其应用于的改进过程中,针对目标检测中边界特征与语义信息的互补性需求,缓解网络中浅层细节与深层语义融合不足的问题。Depth Information Assisted Collaborative Mutual Promotion Network for Single Image Dehazing在图像去雾网络中,不同层级和类型的特征包含着互补的信息(如浅层的

Limiiiing的博客 351

Stanford Algorithms学习:Clustering

第二周的第一个编程作业,是利用贪婪算法来实现一个clustering的问题,和ML里学的unsupervised learning差不多。 Question 1 In this programming problem and the next you'll code up the clustering algorithm from lecture for computing a

likecool21的专栏 2507

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

LeetCode 刷题笔录 Add Two Numbers

You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a link

likecool21的专栏 1806

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

LeetCode刷题笔录Edit Distance

Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.) You have the following 3 operations permitted on a word:

likecool21的专栏 1296

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

LeetCode刷题笔录Minimum Depth of Binary Tree

Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.

likecool21的专栏 1109

LeetCode刷题笔录 Pascal's Triangle II

Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3,3,1]. Note: Could you optimize your algorithm to use only O(k) extra space? 这题比较简单

likecool21的专栏 1043

LeetCode刷题笔录Unique Binary Search Trees

这里有个讲解(印度人口音真难懂)

likecool21的专栏 1043

LeetCode刷题笔录Container With Most Water

Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Fin

likecool21的专栏 1001

LeetCode刷题笔录 Reverse Integer

Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 随手写的一个,正常的读出每一位的数字然后反序: import java.lang.Math; public class Solution { public int revers

likecool21的专栏 941

LeetCode刷题笔录Sum Root to Leaf Numbers

Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number. An example is the root-to-leaf path 1->2->3 which represents the number 123. Find the tota

likecool21的专栏 878

LeetCode刷题笔录Symmetric Tree

Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \ 3 4 4 3 But the f

likecool21的专栏 865

LeetCode刷题笔录Convert Sorted Array to Balanced Binary Search Tree

Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 这题可以kan'chu'lai

likecool21的专栏 855

LeetCode Hot 100 二叉树专题(二)3 题(Java)

本篇文章共 3 题:543. 二叉树的直径、102. 二叉树的层序遍历、108. 将有序数组转换为二叉搜索树。 每道题都统一按「① 题目分析 & 解题思路 → ② 常见解法(附代码)及讲解 → ③ 知识点总结」的顺序组织;代码使用 Java 编写,节点定义沿用 LeetCode 默认的 TreeNode。

2401_88612756的博客 365

LeetCode 每日一题 2026/11/2-2026/11/8

记录了初步解题思路 以及本地实现代码;并不一定为最优 也希望大家能一起探讨 一起进步

AlphaTao的博客 175
上一篇: LeetCode刷题笔录Search in Rotated Sorted Array
下一篇: LeetCode刷题笔录Longest Consecutive Sequence
likecool21
博客等级 码龄14年 14粉丝 123原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值