[Leetcode]316.去除重复字母】的更多相关文章

316. 去除重复字母 给定一个仅包含小写字母的字符串,去除字符串中重复的字母,使得每个字母只出现一次.需保证返回结果的字典序最小(要求不能打乱其他字符的相对位置). 示例 1: 输入: "bcabc" 输出: "abc" 示例 2: 输入: "cbacdcbc" 输出: "acdb" PS: 我把每一个数出现的次数都拿出来,我当前字符比我栈顶的小,并且我栈顶的字符还有多的在后面,我就可以把他替换了,记录一下是否使用 clas…
题目 贪心方法 用一个两个数组vector<int>cnt,vector<bool>in_right_place: string res:目前符合条件的字符串,到代码结束的时候,这个res才是正确的答案 cnt数组 用于记录每个char未来会出现的次数,in_right_place数组判断这个char是否已经在正确的位置上 什么叫做未来会出现呢? 我们拿样例做为例子: 输入: "bcabc" 我们先遍历一遍所有字符串记录cnt 结果是cnt['a']=1,cnt…
316. 去除重复字母 知识点:栈:单调 题目描述 给你一个字符串 s ,请你去除字符串中重复的字母,使得每个字母只出现一次.需保证 返回结果的字典序最小(要求不能打乱其他字符的相对位置). 示例 输入:s = "bcabc" 输出:"abc" 输入:s = "cbacdcbc" 输出:"acdb" 解法一:单调 我们来仔细分析一下这道题目,它结合了很多知识点,因为题目中提出了很多要求. 1.去掉重复的:对于去重最常用的就是s…
给定一个仅包含小写字母的字符串,去除重复的字母使得所有字母出现且仅出现一次.你必须保证返回结果是所有可能结果中的以字典排序的最短结果.例如:给定 "bcabc"返回 "abc"给定 "cbacdcbc"返回 "acdb" 详见:https://leetcode.com/problems/remove-duplicate-letters/description/ C++: class Solution { public: str…
Given a string which contains only lowercase letters, remove duplicate letters so that every letter appear once and only once. You must make sure your result is the smallest in lexicographical order among all possible results. Example 1: Input: "bcab…
Given a string which contains only lowercase letters, remove duplicate letters so that every letter appear once and only once. You must make sure your result is the smallest in lexicographical order among all possible results. Example: Given "bcabc&q…
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. Do not allocate extra space for another array, you must do this in place with constant memory. For example,Given input array A = […
Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length. Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.…
Given a sorted array nums, remove the duplicates in-place such that duplicates appeared at most twice and return the new length. Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra mem…
Given a string, find the length of the longest substring without repeating characters. Examples: Given "abcabcbb", the answer is "abc", which the length is 3. Given "bbbbb", the answer is "b", with the length of 1.…