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

#include <leetcode.h>

静态 Public 成员函数

static int deviceCount (const string &)
 
static int numberOfBeams (vector< string > &)
 

详细描述

在文件 leetcode.h192 行定义.

成员函数说明

◆ deviceCount()

int leetcode::number_of_laser_beams_in_a_bank::Solution::deviceCount ( const string &  str)
static

在文件 leetcode.cpp368 行定义.

368 {
369 int count = 0;
370 for(const char c: str) {
371 if(c == '1') {
372 count++;
373 }
374 }
375 return count;
376 }

被这些函数引用 numberOfBeams().

◆ numberOfBeams()

int leetcode::number_of_laser_beams_in_a_bank::Solution::numberOfBeams ( vector< string > &  bank)
static

在文件 leetcode.cpp346 行定义.

346 {
347 if(bank.size() == 1) {
348 return 0;
349 }
350 int count = 0;
351 int i = 0;
352 int count_i = deviceCount(bank[i]);
353 int j = 1;
354 while(i < j && i < bank.size() && j < bank.size()) {
355 if(deviceCount(bank[j]) == 0) {
356 j++;
357 continue;
358 }
359 const int count_j = deviceCount(bank[j]);
360 count += count_i * count_j;
361 count_i = count_j;
362 i = j;
363 j++;
364 }
365 return count;
366 }

引用了 deviceCount().

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


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