zoukankan      html  css  js  c++  java
  • Leetcode-942 DI String Match(增减字符串匹配)

     1 class Solution
     2 {
     3     public:
     4         vector<int> diStringMatch(string S)
     5         {
     6             vector<int> tmp {0};
     7             for(auto c:S)
     8             {
     9                 int a = tmp.back();
    10                 if(c=='I')
    11                 {
    12                     tmp.push_back(a+1);
    13                 }
    14                 else
    15                 {
    16                     tmp.push_back(a-1);
    17                 }
    18             }
    19         //    for(auto d:tmp)
    20         //        cout << d << endl;
    21             int max = S.size();
    22             vector<int> result;
    23             for(int i = 0;i < max+1;i ++)
    24                 result.push_back(0);
    25             for(int i = 1000;i >= -1000;i --)
    26             {
    27                 for(int j = 0;j < tmp.size();j ++)
    28                 {
    29                     if(tmp[j]==i)
    30                     {
    31                         result[j] = max --;
    32                     }
    33                 }
    34             }
    35             return result;
    36         }
    37 };
  • 相关阅读:
    Linux
    Cookie & Session
    HTTP
    HTTP
    抓包工具
    抓包工具
    抓包工具
    python
    python
    python
  • 原文地址:https://www.cnblogs.com/Asurudo/p/9977564.html
Copyright © 2011-2022 走看看