problemscpp
A collection of my answers to algorithm problems in c++.
静态 Public 成员函数 | 所有成员列表
leetcode::plates_between_candles::Solution类 参考

#include <leetcode.h>

静态 Public 成员函数

static vector< int > platesBetweenCandles (string s, vector< vector< int > > &queries)
 

详细描述

在文件 leetcode.h1580 行定义.

成员函数说明

◆ platesBetweenCandles()

vector< int > leetcode::plates_between_candles::Solution::platesBetweenCandles ( string  s,
vector< vector< int > > &  queries 
)
static

在文件 leetcode.cpp4072 行定义.

4072 {
4073 vector<int> ans;
4074 vector<int> plate_count(s.length());
4075 vector<int> candle_pos;
4076 if(s[0] == '*') {
4077 plate_count[0] = 1;
4078 } else {
4079 plate_count[0] = 0;
4080 candle_pos.push_back(0);
4081 }
4082 for(int i = 1; i < s.length(); i++) {
4083 plate_count[i] = plate_count[i - 1];
4084 if(s[i] == '*') {
4085 plate_count[i]++;
4086 } else {
4087 candle_pos.push_back(i);
4088 }
4089 }
4090 for(auto query: queries) {
4091 int left = query[0];
4092 int right = query[1];
4093 auto li = lower_bound(candle_pos.begin(), candle_pos.end(), left);
4094 if(li == candle_pos.end() || *li > right) {
4095 ans.push_back(0);
4096 continue;
4097 }
4098 auto ri = lower_bound(candle_pos.rbegin(), candle_pos.rend(), right, greater<int>());
4099 if(ri == candle_pos.rend() || *ri < left) {
4100 ans.push_back(0);
4101 continue;
4102 }
4103 ans.push_back(plate_count[*ri] - plate_count[*li]);
4104 }
4105 return ans;
4106 }

引用了 acwing::acwing1929::left , 以及 acwing::acwing1929::right.

被这些函数引用 leetcode::plates_between_candles::TEST().


该类的文档由以下文件生成: