*leetcode763.partitionlabels(代码片段)

Z-Pilgrim Z-Pilgrim     2022-12-06     327

关键词:

https://leetcode.com/problems/partition-labels/description/

const int SIZE = 256;
class Solution 
public:
    
    bool judge( int cnt[], int hash[] ) 
        // bool ret = true;
        for (int i = 0; i < SIZE; i++) 
            if (hash[i] == cnt[i] || !hash[i])continue;
            return false;
        
        
        return true;
    
    
    vector<int> partitionLabels(string s) 
        int mem[SIZE] = 0, hash[SIZE] = 0;
        
        vector<int> ret;
        int cnt = 0;
        for (auto c : s) mem[c] ++;
        for (auto c : s) 
            cnt ++;
            hash[c] ++;
            if (judge(mem, hash)) 
                ret.push_back(cnt);
                cnt = 0;
              
        
        
        return ret;
    
;

 

 

leetcode352&leetcode239&leetcode295&leetcode53&leetcode209(代码片段)

lc352DataStreamasDisjointIntervals可以用treemap解key保存interval的start,value保存interval的end。分别找出当前val的lowerKey(treemap中>val的最小key值,没有就返回null)和higherKey(<val的最大key没有就返回null)有以下几种情况:1)当前插入的key... 查看详情

leetcode分类刷题(续2)(代码片段)

leetcode分类刷题1.递归1.1leetcode509斐波拉契数列1.2leetcode206反转链表1.3leetcode344反转字符串2.分治法2.1归并排序2.2leetcode169多数元素2.3leetcode53最大子序和2.4leetcode215数组中k大元素3.回溯法3.1leetcode78子集(模板)3.2leetcode22括号... 查看详情

leetcode分类刷题(代码片段)

leetcode学习笔记Java版1.数组操作1.1leetcode27移除元素1.2leetcode283移动零1.3leetcode485最大连续1的个数2.链表操作2.1leetcode203移除链表元素2.2leetcode206反转链表3.Java队列Queue3.1leetcode933最近的请求次数(仅一道题目)3.2leetcode239滑动... 查看详情

leetcode每日leetcode一题(代码片段)

其实有些算法思路挺有意思的,决定开始刷刷leetcode,先从简单的题开始吧!非最优解,仅记录分享CSDN链接githubleetcode链接文章目录CSDN链接[githubleetcode链接](https://github.com/smileyqp/frontend_book/blob/master/leetcode.md)6.161、 查看详情

leetcode每日leetcode一题(代码片段)

其实有些算法思路挺有意思的,决定开始刷刷leetcode,先从简单的题开始吧!非最优解,仅记录分享CSDN链接githubleetcode链接文章目录CSDN链接[githubleetcode链接](https://github.com/smileyqp/frontend_book/blob/master/leetcode.md)6.161、 查看详情

链表-leetcode2&leetcode23(代码片段)

链表-Leetcode2&Leetcode23githubrepo地址:https://github.com/GoldenaArcher/js_leetcode,Github的目录大概会更新的更勤快一些。2.AddTwoNumbers题目地址:2.AddTwoNumbersAddTwoNumbers题目如下:Youaregiventwonon-em 查看详情

链表-leetcode2&leetcode23(代码片段)

链表-Leetcode2&Leetcode23githubrepo地址:https://github.com/GoldenaArcher/js_leetcode,Github的目录大概会更新的更勤快一些。2.AddTwoNumbers题目地址:2.AddTwoNumbersAddTwoNumbers题目如下:Youaregiventwonon-em 查看详情

leetcode刷题系列之-多数之和类型

...组合问题衍生到背包问题多数之和1.两数之和-力扣(LeetCode)167.两数之和II-输入有序数组-力扣(LeetCode)15.三数之和-力扣(LeetCode)16.最接近的三数之和-力扣(LeetCode)18.四数之和-力扣(LeetCode... 查看详情

leetcode开篇

开天辟地。力扣LeetCode-TheWorld'sLeadingOnlineProgrammingLearningPlatform 查看详情

leetcode开篇

开天辟地。力扣LeetCode-TheWorld'sLeadingOnlineProgrammingLearningPlatform 查看详情

leetcode开篇

开天辟地。力扣LeetCode-TheWorld'sLeadingOnlineProgrammingLearningPlatform 查看详情

leetcode开篇

开天辟地。力扣LeetCode-TheWorld'sLeadingOnlineProgrammingLearningPlatform 查看详情

leetcode开篇

开天辟地。力扣LeetCode-TheWorld'sLeadingOnlineProgrammingLearningPlatform 查看详情

leetcode单链表相关题目汇总

 leetcode-19-RemoveNthFromEndofList—移除链表中倒数第n个元素 leetcode-21-MergeTwoSortedLists—两个已排序链表归并 leetcode-23-MergekSortedLists—k个已排序链表归并 leetcode-24-SwapNodesinPairs&md 查看详情

leetcode分类刷题(续1)(代码片段)

leetcode算法刷题(续)7.树7.1leetcode144二叉树前序遍历7.2leetcode94二叉树中序遍历7.1leetcode145二叉树后序遍历8.堆8.1leetcode215数组中第k个最大元素8.2leetcode692前k个高频单词10.双指针10.1两个数相加为target,返回下标10.2leetcode... 查看详情

leetcode解题记录

尽量抽空刷LeetCode,持续更新刷题记录在github上面,https://github.com/Zering/LeetCode 2016-09-05300.LongestIncreasingSubsequence问题:https://leetcode.com/problems/longest-increasing-subsequence/分析:http://zering.me/20 查看详情

leetcode刷穿二叉树(代码片段)

这里有leetcode题集分类整理!!!专辑完结,欢迎查看本系列文章:leetcode刷穿二叉树(一)leetcode刷穿二叉树(二)leetcode刷穿二叉树(三)leetcode刷穿二叉树(四)leetcode刷穿 查看详情

leetcode刷穿二叉树(代码片段)

这里有leetcode题集分类整理!!!专辑完结,欢迎查看本系列文章:leetcode刷穿二叉树(一)leetcode刷穿二叉树(二)leetcode刷穿二叉树(三)leetcode刷穿二叉树(四)leetcode刷穿 查看详情