给定一组数(未排序), 求它们的所有组合可能. 如给定{1 2 3}, 返回: [ [] [1] [2] [3] [1 2] [1 3] [2 3] [1 2 3] ] 算法思路: 对数组排序, 从小到大; 令 i = 0, 对已有组合v从后往前进行如下操作 v的最后1个组合内加入第i个元素; 将新组合加入到v中 算法的理解可以通过一个例子来看: 给定S = {1 2 3}, v = [[]] i = 0, j = 1, v = [[] [1]] // back().push_back(S[0]…
给定一组数(未排序, 可能有重复元素), 求出所有可能的组合. 算法和无重复元素的相似. 唯一需要注意的是, 如果当前的数字和之前的相同, 算法就只会在结尾数字是此数字的组合后加上此数字. 比如现在是[[] [1] [1 2] [2]], 当前数字是2, 就只会增加[1 2 2] [2 2] 代码: class Solution { public: vector<vector<int> > subsetsWithDup(vector<int> &S) { sor…
本内容是LeetCode第三道题目:无重复字符的最大子串 # -*- coding: utf-8 -*- """ Created on Sun Mar 10 20:14:53 2019 @author: Administrator Given a string, find the length of the longest substring without repeating characters. Example 1: Input: "abcabcbb"…
LeetCode 第 3 题:无重复字符的最长子串 (滑动窗口) 方法:滑动窗口 滑动窗口模板问题:右指针先走,满足了一定条件以后,左指针向前走,直到不满足条件. 特点:左右指针的方向是一致的,并且是不回头的. C++ 代码: #include <iostream> #include <string> using namespace std; class Solution { public: int lengthOfLongestSubstring(string s) { int…
题目:http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=11313 湖师大的比赛,见我的另一篇水题题解,这里要说的是我YY出来的C题,无重复元素序列的最长公共子序列. 用常规的做法会超时,于是我YY出来一个方法,记录第一组各个数字的位置,读取第二组,把第一组出现的相同数字的位置放入序列,没出现就不放...然后就转成LIS题目了... 具体用例子来说明下,比如两个序列 3 2 1 5 4 2 1 5 4 3 很明显,LCS…
Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the absolute difference between i and j is at most k. Example 1: Input: nums = [1,2,3,1], k = 3 Output:…
Given an array of integers, find out whether there are two distinct indices i and j in the array such that the absolute difference between nums[i] and nums[j] is at most t and the absolute difference between i and j is at most k. Example 1: Input: nu…
Medium! 题目描述: 给定一个字符串,找出不含有重复字符的 最长子串 的长度. 示例: 给定 "abcabcbb" ,没有重复字符的最长子串是 "abc" ,那么长度就是3. 给定 "bbbbb" ,最长的子串就是 "b" ,长度是1. 给定 "pwwkew" ,最长子串是 "wke" ,长度是3.请注意答案必须是一个子串,"pwke" 是 子序列 而不是子串…
欢迎评论区交流. package leetcode.day_12_04; /** * 给定一个字符串 s ,请你找出其中不含有重复字符的最长子串的长度. * <p> * 示例1: * <p> * 输入: s = "abcabcbb" * 输出: 3 * 解释: 因为无重复字符的最长子串是 "abc",所以其长度为 3. * 示例 2: * <p> * 输入: s = "bbbbb" * 输出: 1 * 解释:…
[题目描述] 给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度. 示例 1: 输入: "abcabcbb"输出: 3 解释: 因为无重复字符的最长子串是 "abc",所以其长度为 3.示例 2: 输入: "bbbbb"输出: 1解释: 因为无重复字符的最长子串是 "b",所以其长度为 1.示例 3: 输入: "pwwkew"输出: 3解释: 因为无重复字符的最长子串是 "wke&qu…