力扣:1805. 字符串中不同整数的数目

 

1、感觉写复杂了,将就看一下吧(有空再优化一下)

首先将数字串给读取下来,读取的时候判断前导0,

然后判断读取到的数字串有多少相等的。

然后输出不想的的数字串数。

class Solution {
public:
    int numDifferentIntegers(string word) {
        int thesize=word.size();
        vector<vector<char>> nums;
        vector<char> then;
        int label=0;
        while(label<thesize)
        {
            while(label<thesize&&(word[label]<'0'||word[label]>'9')) ++label;
            while(label<thesize&&(word[label]<='9'&&word[label]>='0'))
            {
               if(!then.empty()||word[label]!='0')then.push_back(word[label]);
               else if(label+1<thesize&&(word[label+1]<'0'||word[label+1]>'9'))then.push_back(word[label]);
               else if(label+1==thesize) then.push_back(word[label]);
                ++label;
            }
            then.push_back('\0');
            if(then[0]!='\0')nums.push_back(then);
            then.clear();
        }
        thesize=label=nums.size();
        if(label<=1) return label;
        for(int i=0;i<thesize-1;++i)
          for(int j=i+1;j<thesize;++j)
          {
              if(nums[i].size()!=nums[j].size()) continue;
              if(jug_strsame(nums[i],nums[j]))
              {
                  --label;
                  break;
              }
          }
        return label;
        
    }
    bool jug_strsame(vector<char>& s1,vector<char>& s2)
    {
        for(int i=0;s1[i];++i) if((s1[i]^s2[i])!=0) return false;
        return true;
    }
};

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值