[LeetCode]87. Scramble String

上网第二课:办了百兆宽带,为什么测速只有一半? 最慢的那一环。 阅读详情

[LeetCode]87. Scramble String

题目描述

这里写图片描述

思路

对于题目中描述的扰乱字符串,可能存在多个

递归解决
当前输入的两个字符串如果相等,即返回true
否则 对i从1到len-1
判断 s1(0,i) 与 s2(0,i)或则s2(len - i, len - 1)是否满足扰乱串的条件
s1(i,len - 1) 与 s2(i, len - 1)或则s2(0, len - i)是否满足
若均满足返回true
否则返回false

代码

#include <iostream>
#include <string>
#include <vector>

using namespace std;



class Solution {
public:
    bool isScramble(string s1, string s2) {
        if (s1 == s2)
            return true;
        vector<int> count(26, 0);
        for (int i = 0; i < s1.size(); ++i) {
            count[s1[i] - 'a']++;
            count[s2[i] - 'a']--;
        }

        for (int p : count) {
            if (p != 0)
                return false;
        }

        for (int i = 1; i < s1.size(); ++i) {
            if (isScramble(s1.substr(0, i), s2.substr(0, i)) && isScramble(s1.substr(i), s2.substr(i)))
                return true;
            if (isScramble(s1.substr(0, i), s2.substr(s1.size() - i)) && isScramble(s1.substr(i), s2.substr(0, s1.size() - i)))
                return true;
        }
        return false;
    }
};

int main() {
    Solution s;
    cout << s.isScramble("ab", "ba") << endl;

    system("pause");
    return 0;
}
【DeepSeek R1构建本地RAG知识库】数据结构化清洗-工作流自动清洗 在构建本地RAG知识库时,数据结构化清洗是关键但繁琐的步骤。传统方法效率低且易出错,而低代码/无代码平台如Dify提供了更高效的解决方案。Dify通过可视化工作流设计,集成大模型智能处理,支持多格式输入输出,无需编码即可完成复杂的数据清洗任务。文章详细介绍了数据结构化的核心困境、目标、价值及类型,并比较了TXT与Markdown在RAG系统中的适用性。最后,通过Dify平台实战演示了如何在20分钟内完成规则制度文档的结构化清洗,输出标准化数据,展示了自动化工作流在数据处理中的高效性和便捷性。 阅读详情

相关推荐

基于gm/id方法的折叠式共源共栅放大器设计实践

本文详细介绍了基于gm/id设计方法进行折叠式共源共栅放大器设计的完整流程。该方法通过确定晶体管的跨导效率(gm/id)作为核心设计参数,将复杂的放大器设计转化为有明确路径的优化问题。文章以设计一个增益80dB、带宽1GHz的两级放大器为例,逐步拆解了从指标分解、关键晶体管工作点选取、到实战仿真与微调的全过程,特别强调了第二级设计对稳定性的影响以及相位裕度的调试技巧。

w8x9y0z1的博客 414

Leetcode 87. 扰乱字符串

题目要求==判断能不能建成二叉树 1.字母都要一样 2.1 s1没被挑选,s1的前k个字符和s2的前k个字符构成扰乱字符串,s1后面的字符和s2后面的字符也构成扰乱字符串 2.2 s1被挑选,s1的前k个字符和s2的后k个字符构成扰乱字符串,s1后面的字符和s2前面的字符也构成扰乱字符串 k是1……size-1【保证左右都不为空】 class Solution { public: ...

Bendaai的博客 1094

基于图神经网络的社交网络虚假账号检测系统 (Graph-based Fake Account Detection System, GFADS)

FOLLOWSRETWEETSSHAREDCOMMENTSLIKESMENTIONSUseruser_idusernamejoin_datebioavatar_urllocationverifiedis_fakeLOAD CSV这是决定模型性能的关键环节,需结合和。XXedge_indexy新账号缺乏历史数据和丰富关系。全网图可能包含数亿节点和数十亿边,难以直接训练。社交网络是动态变化的,虚假账号策略也在不断进化。获取大规模、高质量的真实/虚假账号标注数据非常困难。

Deng945201314的博客 1481

LeetCode --- 87. Scramble String

题目链接:Scramble String Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively. Below is one possible representation of s1 = "great":

makuiyu的专栏 2544

MiniMax H3 + ComfyUI 工作流搭建指南:从整合包到视频生成

AI视频生成正成为内容创作的新基础设施,而ComfyUI作为可视化工作流引擎,将复杂的模型推理过程拆解为节点与连线,让本地视频生成变得可复用、可批量。理解这一原理后,用户无需编写代码,只需掌握模型加载、提示词控制、采样与解码的基本链路,即可搭建出稳定的视频生产管线。MiniMax H3作为前沿视频生成模型,在ComfyUI中通过权重文件和自定义节点落地,配合整合包可大幅降低环境配置门槛。从硬件评估、目录结构到节点连接与参数调优,本文系统性梳理了从零跑通一条视频生成工作流的完整路径,帮助用户在批量素材生成、风

weixin_29057065的博客 411

NX二次开发常用函数——从一个坐标系到另一个坐标系的转换(UF_MTX4_csys_to_csys )相同体坐标转化

本文介绍了在项目开发中实现坐标转换的方法,重点解析了两个关键函数UF_MTX4_csys_to_csys和UF_MTX4_vec3_multiply的使用。通过4个变换矩阵(transform1-4)实现工作坐标系与绝对坐标系之间的相互转换,并以圆柱体为例详细说明了坐标转换的具体实现过程,包括原点、X/Y轴方向的转换处理。相比之前采用的if-else判断方法,这种矩阵转换方式在代码复杂度和运行效率上都更具优势。

weixin_47753171的博客 599

scramble-string

【题目描述】Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively. Below is one possible representation of s1 =“great”: great / gr eat / \...

weixin_36909758的博客 527

【AI Agent】Harness Engineering实践

Harness(运行宿主)是围绕 LLM构建的一套确定性工程系统,其核心职责是:承认模型的固有局限,用可控的工程手段逐一弥补,使"强大但不可靠的推理引擎"变成"可信赖的生产级Agent"模型 是发动机——提供原始动力Agent 是驾驶员——做出决策Harness 是道路、地图、护栏、仪表盘、维修站和质检线——确保行驶安全有序没有Harness,模型越强,可能只是更快地制造混乱。

sysu_lluozh 190

LeetCode 87. Scramble String(字符串扰乱)

原题网址:https://leetcode.com/problems/scramble-string/ Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively. Below is one possible

James Pan 1809

168、OIS光学防抖系统设计:陀螺仪标定、音圈马达驱动与滚珠式/悬丝式结构选型

本文总结了OIS光学防抖系统设计中的关键问题与解决方案。作者通过实际案例指出,陀螺仪标定需重视零偏、灵敏度和温度补偿问题,音圈马达驱动需采用电流环控制并优化相位补偿。在机械结构选型方面,滚珠式适合大角度补偿但存在回差问题,悬丝式精度高但受重力影响,需根据应用场景选择。系统联调建议从开环到闭环逐步验证,注意陀螺仪与驱动频率匹配。最后给出5条经验建议:关注陀螺仪信噪比而非分辨率、预留标定余量、重视机械结构公差、配备专业调试工具、协调OIS与电子防抖的分工配合。文章强调OIS调试需针对不同模组特性进行反复测试与标

zzfmlxs的博客 43

42、InfiniBand技术详解:QP状态机、操作及错误处理

本文深入解析InfiniBand技术中的核心组件QP(Queue Pair)状态机、工作请求处理机制、支持的操作类型及错误处理策略。详细介绍了QP的创建与状态转换流程,包括INIT、RTR、RTS等关键状态,并提供了状态修改的代码示例。文章还探讨了工作请求的发布、资源使用限制、围栏机制以及重试和RNR流程,帮助开发者理解通信可靠性保障机制。此外,涵盖了多播组的应用场景与API使用方法,并对比了用户空间与内核级RDMA API的调用差异,最后给出了实践建议和常见问题解答,为构建高性能分布式系统提供技术指导。

oauth7security的博客 131

LeetCode(87) Scramble String

题目 Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively. Below is one possible representation of s1 = "great": great /

指尖飞舞 970

【SCADA】KingSCADA将数据插入SQLServer的方法

1、创建数据库及数据表格;2、配置ODBC数据源。3、通过KingSCADA与数据库建立连接,将数据写入数据库对应表格。

做有价值的事,积累有价值的笔记! 4958

[Leetcode]87. Scramble String

[Leetcode]87.Scramble String 本题难度: Hard Topic: divide and conquere Description Given a strings1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursivel...

weixin_30856965的博客 96

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

LeetCode 87 scramble-string

LeetCode 87 一开始我的思路是把所有的scramble的strings都求出来,然后看看另外一个是否在里面。快速可以优化的地方就是记住已经求过的scramble的strings。 代码相对比较容易,每次把string都拆成两部分,然后求scramble的strings,再组合在一起: def isScrambleSlow(self, s1: str, s2: str) ->...

frankguodongchen的博客 180

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

LeetCode87 Scramble String

LeetCode87 Scramble String问题来源LeetCode87问题描述 Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively. Below is one possible representat

yanqinghe123的专栏 411

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

leetcode 87. Scramble String 二分法

leetcode 87. Scramble String public class Solution { public static void main(String[] args){ String s1 = "ab"; String s2 = "ba"; Solution s = new Solution(); System.out.println(s.isScr

独钓寒江雪 384

Leetcode 87 Scramble String

思路:我成功地写出了如果只修改一次的话,判断是否是scramble string的方法。但很可惜,这边修改的节点可以是多个,我觉得我这种方法继续写下去应该是可以实现题目要求的,但是我想了好久,不会哈哈哈。我猜应该用recursive的方法来继续写下去?我也不太确定。但是我真的是太不喜欢recursive方法,哎但是,好像dfs,dp都和recursion有着一点关系。真得好好练练。我看了high votes answer,发现人家也是recursive的方法。真的我看懂他这个代码都花了一个多小时吧。烦死了.

GoodJobJasper的博客 266

LeetCode: 87. Scramble String

LeetCode: 87. Scramble String 题目描述 Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively. Below is one possible representation of s1 =...

杨领well的专栏 843

LeetCode87——Scramble String

LeetCode87——Scramble String 目前递归解决的方法

上善若水 537

[leetcode] 87. Scramble String

Description Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively. Below is one possible representation of s1 = “great”: great / gr ...

Learning from the mistakes 285

【Leetcode】87. Scramble String

题目地址: https://leetcode.com/problems/scramble-string/ 给定两个字符串s1s_1s1​和s2s_2s2​,允许将s1s_1s1​做以下操作: 1、若s1=x+ys_1=x+ys1​=x+y,xxx和yyy都是s1s_1s1​的非空子串,那么可以将s1s_1s1​变成y+xy+xy+x; 2、在1的基础上,对xxx和yyy继续做与111相同操作。也就是说,一旦进行了1的操作,还可以继续将xxx和yyy重新视为s1s_1s1​来做分割交换的操作。 问s1s_1s

数学、算法爱好者的博客 218

【To Understand !!! DP or 递归】LeetCode 87. Scramble String

LeetCode 87. Scramble String 参考链接:[1]https://blog.csdn.net/makuiyu/article/details/44926439 [2]http://www.cnblogs.com/grandyang/p/4318500.html Solution1: 递归 class Solution { public: bool isSc...

Allenlzcoder的博客 310

87. Scramble String Leetcode Python

Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively. Below is one possible representation of s1 = "great": great / \ gr

hyperbolechi的专栏 845

LeetCode String 87 Scramble String

87. Scramble String Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively. Below is one possible representation of s1 = “great”: To scramb...

Yi Jiao's Blog 164

【一天一道LeetCode】#87. Scramble String

一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder‘s Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substr

ZeeCoder 2948
上一篇: [LeetCode]11. Container With Most Water
下一篇: [LeetCode]205. Isomorphic Strings
charon____
博客等级 码龄11年 3粉丝 202原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值