• leetcode 185周周赛 字节专场


    5388. 重新格式化字符串

    string reformat(string s) {
        queue<char> nums, letters;
        for(char c:s) {
            if('0' <= c && c <= '9') nums.push(c);
            else if('a' <= c && c <= 'z') letters.push(c);
        }
        int len1 = nums.size(), len2 = letters.size();
        if(abs(len1-len2) > 1) return "";
        string ans = "";
        if(len1 == 0 || len2 == 0) {
            if(len1 == 1 || len2 == 1) {
                ans += len1 == 1 ? nums.front() : letters.front();
                return ans;
            }
            return "";
        }
    
        if(len1 >= len2) {
            while(!letters.empty()) {
                ans += nums.front();
                nums.pop();
                ans += letters.front();
                letters.pop();
            }
            if(len1 > len2) ans += nums.front();
        }
        else {
            while(!nums.empty()) {
                ans += letters.front();
                letters.pop();
                ans += nums.front();
                nums.pop();
            }
            ans += letters.front();
        }
        return ans;
    }
    

    1 5389.点菜展示表

    vector<vector<string>> displayTable(vector<vector<string>>& orders) {
        set<string> foodList;
        map<int, map<string,int> > tableList;
        for(auto& o:orders) {
            foodList.insert(o[2]);
            tableList[stoi(o[1])][o[2]]++;
        }
        vector<string> title;
        title.push_back("titile");
        for(auto& f:foodList) {
            title.push_back(f);
        }
        vector<vector<string> > ans;
        ans.push_back(title);
        for(auto& t:tableList) {
            title.push_back(to_string(t.first));
            for(auto& f:foodList) {
                title.push_back(to_string(t.second[f]));
            }
            ans.push_back(title);
        }
        return ans;
    }
    
  • 相关阅读:
    423. Reconstruct Original Digits from English
    400. Nth Digit
    397. Integer Replacement
    396. Rotate Function
    365. Water and Jug Problem
    335. Self Crossing
    319. Bulb Switcher
    线段树-hdu2795 Billboard(贴海报)
    线段树---求逆序数
    线段树——单点替换区间最值
  • 原文地址:https://www.cnblogs.com/huangming-zzz/p/12730964.html
Copyright © 2020-2023  润新知