Leetcode-5175 Can Make Palindrome from Substring(构建回文串检测)

 1 #define _for(i,a,b) for(int i = (a);i < b;i ++)
 2 #define _rep(i,a,b) for(int i = (a);i > b;i --)
 3
 4 class Solution
 5 {
 6     public:
 7         vector<bool> canMakePaliQueries(string s, vector<vector<int>>& queries)
 8         {
 9             vector<bool> v;
10             long long sum[100003][27];
11             memset(sum,0,sizeof(sum));
12             sum[1][s[0]-‘a‘] ++;
13             _for(i,2,s.size()+1)
14             {
15                 memcpy(sum[i],sum[i-1],sizeof(sum[i]));
16                 sum[i][s[i-1]-‘a‘] ++;
17             }
18
19             _for(i,0,queries.size())
20             {
21                 int rnt = 0;
22                 _for(j,0,27)
23                 {
24                     int tmp = sum[queries[i][1]+1][j]-sum[queries[i][0]][j];
25                     if(tmp&0x1)
26                         rnt ++;
27                 }
28                 if(rnt/2<=queries[i][2])
29                     v.push_back(true);
30                 else
31                     v.push_back(false);
32             }
33             return v;
34         }
35 };

原文地址:https://www.cnblogs.com/Asurudo/p/11442044.html

时间: 2024-10-15 06:07:00

Leetcode-5175 Can Make Palindrome from Substring(构建回文串检测)的相关文章

[LeetCode] Find the Closest Palindrome 寻找最近的回文串

Given an integer n, find the closest integer (not including itself), which is a palindrome. The 'closest' is defined as absolute difference minimized between two integers. Example 1: Input: "123" Output: "121" Note: The input n is a po

[LeetCode] Palindrome Partitioning II 拆分回文串之二

Given a string s, partition s such that every substring of the partition is a palindrome. Return the minimum cuts needed for a palindrome partitioning of s. For example, given s = "aab", Return 1 since the palindrome partitioning ["aa"

Gym 100952H Special Palindrome 非递减的回文串、dfs打表、查数列网站OEIS

H - H Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice Gym 100952H Description standard input/output Statements A sequence of positive and non-zero integers called palindromic if it can be read the s

132 Palindrome Partitioning II 分割回文串 II

给定一个字符串 s,将 s 分割成一些子串,使每个子串都是回文串.返回 s 符合要求的的最少分割次数.例如,给出 s = "aab",返回 1 因为进行一次分割可以将字符串 s 分割成 ["aa","b"] 这样两个回文子串.详见:https://leetcode.com/problems/palindrome-partitioning-ii/description/ class Solution { public: int minCut(str

Palindrome(最长回文串manacher算法)O(n)

Palindrome Time Limit:15000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Description Andy the smart computer science student was attending an algorithms class when the professor asked the students a simple question, "

leetcode每日一题:409. 最长回文串

409. 最长回文串 给定一个包含大写字母和小写字母的字符串,找到通过这些字母构造成的最长的回文串. 在构造过程中,请注意区分大小写.比如 "Aa" 不能当做一个回文字符串. 注意: 假设字符串的长度不会超过 1010. 输入: "abccccdd" 输出: 7 解释: 我们可以构造的最长的回文串是"dccaccd", 它的长度是 7. 题目描述:先排好序,然后遍历一遍,左右相同的就可以凑成一对,最后再判断一下能否再加一个单个的,如果没达到字符串

[LeetCode] Longest Palindrome 最长回文串

Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters. This is case sensitive, for example "Aa" is not considered a palindrome here. Note: Assume the leng

LeetCode 5:Longest Palindromic Substring(最长回文串)

Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring. 思路一:(超时)简单的截取长度为length(length递减)的字串,判断其是否为回文串.第一个满足要求的回文串最长. public class S

LeetCode 131. 分割回文串(Palindrome Partitioning)

131. 分割回文串 131. Palindrome Partitioning 题目描述 给定一个字符串 s,将 s 分割成一些子串,使每个子串都是回文串. 返回 s 所有可能的分割方案. LeetCode131. Palindrome Partitioning中等 示例: 输入: "aab" 输出: [ ??["aa","b"], ??["a","a","b"]] Java 实现 略