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

#include <leetcode.h>

静态 Public 成员函数

static int * get_p (char ch, int *a, int *b, int *c)
 
static string longestDiverseString (int a, int b, int c)
 
static void sort (char ch[3], int a, int b, int c)
 

详细描述

在文件 leetcode.h1017 行定义.

成员函数说明

◆ get_p()

int * leetcode::longest_happy_string::Solution::get_p ( char  ch,
int *  a,
int *  b,
int *  c 
)
static

在文件 leetcode.cpp2573 行定义.

2573 {
2574 switch(ch) {
2575 case 'a': return a;
2576 case 'b': return b;
2577 case 'c': return c;
2578 default: return nullptr;
2579 }
2580 }

被这些函数引用 longestDiverseString().

◆ longestDiverseString()

string leetcode::longest_happy_string::Solution::longestDiverseString ( int  a,
int  b,
int  c 
)
static

在文件 leetcode.cpp2507 行定义.

2507 {
2508 auto oss = ostringstream();
2509 int count = 0;
2510 char prev = '0';
2511 char ch[3] = {};
2512 sort(ch, a, b, c);
2513 while(a != 0 || b != 0 || c != 0) {
2514 if(!(count == 2 && prev == ch[2] && *get_p(ch[2], &a, &b, &c) > 0)) {
2515 oss << ch[2];
2516 (*get_p(ch[2], &a, &b, &c))--;
2517 if(prev == ch[2]) {
2518 count++;
2519 } else {
2520 prev = ch[2];
2521 count = 1;
2522 }
2523 } else if(!(count == 2 && prev == ch[1]) && *get_p(ch[1], &a, &b, &c) > 0) {
2524 oss << ch[1];
2525 (*get_p(ch[1], &a, &b, &c))--;
2526 if(prev == ch[1]) {
2527 count++;
2528 } else {
2529 prev = ch[1];
2530 count = 1;
2531 }
2532 } else if(!(count == 2 && prev == ch[0]) && *get_p(ch[0], &a, &b, &c) > 0) {
2533 oss << ch[0];
2534 (*get_p(ch[0], &a, &b, &c))--;
2535 if(prev == ch[0]) {
2536 count++;
2537 } else {
2538 prev = ch[0];
2539 count = 1;
2540 }
2541 } else {
2542 return oss.str();
2543 }
2544 sort(ch, a, b, c);
2545 }
2546 return oss.str();
2547 }
static int * get_p(char ch, int *a, int *b, int *c)
Definition: leetcode.cpp:2573
static void sort(char ch[3], int a, int b, int c)
Definition: leetcode.cpp:2549

引用了 get_p() , 以及 sort().

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

◆ sort()

void leetcode::longest_happy_string::Solution::sort ( char  ch[3],
int  a,
int  b,
int  c 
)
static

在文件 leetcode.cpp2549 行定义.

2549 {
2550 int minimum = a;
2551 ch[0] = 'a';
2552 int maximum = b;
2553 ch[2] = 'b';
2554 if(minimum > b) {
2555 minimum = b;
2556 ch[0] = 'b';
2557 }
2558 if(minimum > c) {
2559 minimum = c;
2560 ch[0] = 'c';
2561 }
2562 if(maximum < a) {
2563 maximum = a;
2564 ch[2] = 'a';
2565 }
2566 if(maximum < c) {
2567 maximum = c;
2568 ch[2] = 'c';
2569 }
2570 ch[1] = 'a' + 'b' + 'c' - ch[0] - ch[2];
2571 }

被这些函数引用 longestDiverseString().


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