https://discuss.leetcode.com/topic/30941/here-is-a-10-line-template-that-can-solve-most-substring-problems

总结的还是不错的:

int findSubstring(string s){
vector<int> map(,);
int counter; // check whether the substring is valid
int begin=, end=; //two pointers, one point to tail and one head
int d; //the length of substring for() { /* initialize the hash map here */ } while(end<s.size()){ if(map[s[end++]]-- ?){ /* modify counter here */ } while(/* counter condition */){ /* update d here if finding minimum*/ //increase begin to make it invalid/valid again if(map[s[begin++]]++ ?){ /*modify counter here*/ }
} /* update d here if finding maximum*/
}
return d;
}

substring类型题目的解题模板的更多相关文章

  1. 类型推导:函数模板与auto

    1.从函数模板谈起 函数模板的类型推导机制是在c++98时代就有的,auto的类型推导机制与其基本一致,所以先理解函数模板类型推导. 函数模板可以用如下代码框架表示: #template<typ ...

  2. leetcode 链表类型题目解题总结

    最基础的方式要做到非常熟练,要熟练到不思考就能写,但又需明白各处的要求和陷阱 合并两个有序链表的操作,在前面加上一个初始节点,注意while循环和退出时的处理,理解如何处理其中一个链表遍历完的情况 L ...

  3. leetcode math类型题目解题总结

    2. Add Two Numbers https://leetcode.com/problems/add-two-numbers/description/ class Solution { publi ...

  4. LeetCode 3 Longest Substring Without Repeating Characters 解题报告

    LeetCode 第3题3 Longest Substring Without Repeating Characters 首先我们看题目要求: Given a string, find the len ...

  5. Sum 类型题目总结

    Sum类的题目一般这样: input: nums[], target output: satisfied arrays/ lists/ number 拿到题目,首先分析: 1. 是几个数的sum 2. ...

  6. LeetCode数组解题模板

    一.模板以及题目分类 1.头尾指针向中间逼近 ; ; while (pos1<pos2) { //判断条件 //pos更改条件 if (nums[pos1]<nums[pos2]) pos ...

  7. LeetCode链表解题模板

    一.通用方法以及题目分类 0.遍历链表 方法代码如下,head可以为空: ListNode* p = head; while(p!=NULL) p = p->next; 可以在这个代码上进行修改 ...

  8. nSum “已知target再求和”类型题目总结:n-2重循环+left/right

    Sum类的题目一般这样: input: nums[], target output: satisfied arrays/ lists/ number 拿到题目,首先分析: 1. 是几个数的sum 2. ...

  9. [LeetCode] 3. Longest Substring Without Repeating Characters 解题思路

    Given a string, find the length of the longest substring without repeating characters. For example, ...

随机推荐

  1. 深入理解 C 指针阅读笔记 -- 第二章

    Chapter2.h #ifndef __CHAPTER_2_ #define __CHAPTER_2_ /*<深入理解C指针>学习笔记 -- 第二章*/ /* 内存泄露的两种形式 1.忘 ...

  2. springAOP注解方式实现日志操作

    通过自定义注解调用方法执行日志存储: package com.zktx.platform.log2; import java.lang.reflect.Method; import java.util ...

  3. bzoj2260: 商店购物&&4349: 最小树形图

    最小树形图问题啊 最小树形图是撒哩,就是给你一个有向图,确定一个根,要你到达所有点,那棵最短路径树的总边权 做这个用的是朱(jv)刘(lao)算法. 首先假如有多个联通块就无解啦 对应每个点(除了根) ...

  4. Spring Boot:Exception parsing document: template="index", line 7 - column 3

    转自:https://blog.csdn.net/u010429286/article/details/75447561

  5. c#为程序添加全局热键的方法

    在程序失去焦点或者在后台运行时,可以通过使用全局热键的方式,进行一些快捷的操作,如QQ默认操作中ctrl+alt+A调出截图功能. 在Windows中实现热键功能需要使用win32的Api函数Regi ...

  6. ServletContextAware、ServletRequestAware、ServletResponseAware、SessionAware

    转自:ServletContextAware.ServletRequestAware.ServletResponseAware.SessionAware Struts 2提供了Aware接口.Awar ...

  7. IDEA中Lombok插件的安装与使用

    背景   我们在开发过程中,通常都会定义大量的JavaBean,然后通过IDE去生成其属性的构造器.getter.setter.equals.hashcode.toString方法,当要对某个属性进行 ...

  8. POJ 1703 带权并查集

    直接解释输入了: 第一行cases. 然后是n和m代表有n个人,m个操作 给你两个空的集合 每个操作后面跟着俩数 D操作是说这俩数不在一个集合里. A操作问这俩数什么关系 不能确定:输出Not sur ...

  9. RMS:均方根值,RMSE:均方根误差,MSE:标准差

    .均方根值(RMS),有时也称方均根.效值.英语写为:Root Mean Square(RMS). 美国传统词典的定义为:The square root of the average of squar ...

  10. javascript的基础知识及面向对象和原型属性

    自己总结一下javascript的基础知识,希望对大家有用,也希望大家来拍砖,毕竟是个人的理解啊 1.1 类型检查:typeof(验证数据类型是:string) var num = 123; cons ...