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

#include <leetcode.h>

静态 Public 成员函数

static int minMovesToMakePalindrome (string s)
 

详细描述

在文件 leetcode.h1514 行定义.

成员函数说明

◆ minMovesToMakePalindrome()

int leetcode::minimum_number_of_moves_to_make_palindrome::Solution::minMovesToMakePalindrome ( string  s)
static

在文件 leetcode.cpp3898 行定义.

3898 {
3899 int ans = 0;
3900 for(int left = 0, right = s.size() - 1; left < right; left++) {
3901 bool even = false;
3902 for(int i = right; left != i; i--) {
3903 if(s[left] == s[i]) {
3904 even = true;
3905 // 字母出现偶数次的情况,模拟交换
3906 for(; i < right; i++) {
3907 swap(s[i], s[i + 1]);
3908 ans++;
3909 }
3910 right--;
3911 break;
3912 }
3913 }
3914 if(!even) {
3915 // 字母出现奇数次的情况,计算它距离中间还有多少距离
3916 ans += s.size() / 2 - left;
3917 }
3918 }
3919 return ans;
3920 }

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

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


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