写作前面
主要四道题目,1道easy,1道medium,2道hard。
其中前两道题干略长,需要理解,但写出来并不复杂,难在理解题意;
后两道略偏数据结构和算法。
主要题目如下:
- Crawler log folder
 
- Maximum Profit of Operating a Centennial Wheel
 
- Throne Inheritance
 
- Maximum Number of Achievable Transfer Requests
 
Crawler log folder
原题链接
Easy
解答:
1 2 3 4 5 6 7 8 9 10 11 12 13
   | class Solution { public:     int minOperations(vector<string>& logs) {         int res=0;         for(string s: logs){             if(s=="../"){if(res>0)res--;}             else if(s=="./"){                 res=res;             }else{res++;}         }         return res>=0? res:0;     } };
  | 
 
Maximum Profit of Operating a Centennial Wheel
原题链接
Medium
解答:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
   | class Solution { public:     int minOperationsMaxProfit(vector<int>& customers, int boardingCost, int runningCost) {         int maxProfit = INT_MIN;         int min=0, i=0, remaining= customers[i];         int totalboarded=0;         while(true){             int board = remaining>3? 4:remaining;             remaining-= board;             totalboarded+=board;                          if(i+1<customers.size()){                 remaining +=customers[i+1];             }             i++;             int currentProfit=(totalboarded*boardingCost)-(i*runningCost);             if(currentProfit>maxProfit){                 min=i;             }             maxProfit=max(maxProfit,(totalboarded*boardingCost)-(i*runningCost));             if(remaining==0){                 break;             }         }         return maxProfit<=0? -1:min;     } };
  | 
 
Throne Inheritance
原题链接
Maximum Number of Achievable Transfer Requests
原题链接