编写一个函数
int solution(char *S);
从给出的字符串 S 中,找到并返回这样一个字符的下标(下标从 0 开始算), 使得这个字符左边的子字符串,刚好与右边的子字符串相反 (但如果这样的字符不存在的话,返回 −1)。
例如,给出这样一个字符串
"racecar"
你的函数应该返回 3,因为对于下标为 3 的字符 e, 其左边相邻的子字符串是 "rac", 而右边相邻的子字符串是 "car"。
注: 与空字符串(长度为 0 的字符串)相反的还是一个空字符串。
假定:
- S 长度范围 [0..2,000,000].
编写一个函数
int solution(string &S);
从给出的字符串 S 中,找到并返回这样一个字符的下标(下标从 0 开始算), 使得这个字符左边的子字符串,刚好与右边的子字符串相反 (但如果这样的字符不存在的话,返回 −1)。
例如,给出这样一个字符串
"racecar"
你的函数应该返回 3,因为对于下标为 3 的字符 e, 其左边相邻的子字符串是 "rac", 而右边相邻的子字符串是 "car"。
注: 与空字符串(长度为 0 的字符串)相反的还是一个空字符串。
假定:
- S 长度范围 [0..2,000,000].
编写一个函数
int solution(string &S);
从给出的字符串 S 中,找到并返回这样一个字符的下标(下标从 0 开始算), 使得这个字符左边的子字符串,刚好与右边的子字符串相反 (但如果这样的字符不存在的话,返回 −1)。
例如,给出这样一个字符串
"racecar"
你的函数应该返回 3,因为对于下标为 3 的字符 e, 其左边相邻的子字符串是 "rac", 而右边相邻的子字符串是 "car"。
注: 与空字符串(长度为 0 的字符串)相反的还是一个空字符串。
假定:
- S 长度范围 [0..2,000,000].
编写一个函数
class Solution { public int solution(string S); }
从给出的字符串 S 中,找到并返回这样一个字符的下标(下标从 0 开始算), 使得这个字符左边的子字符串,刚好与右边的子字符串相反 (但如果这样的字符不存在的话,返回 −1)。
例如,给出这样一个字符串
"racecar"
你的函数应该返回 3,因为对于下标为 3 的字符 e, 其左边相邻的子字符串是 "rac", 而右边相邻的子字符串是 "car"。
注: 与空字符串(长度为 0 的字符串)相反的还是一个空字符串。
假定:
- S 长度范围 [0..2,000,000].
编写一个函数
int solution(String S);
从给出的字符串 S 中,找到并返回这样一个字符的下标(下标从 0 开始算), 使得这个字符左边的子字符串,刚好与右边的子字符串相反 (但如果这样的字符不存在的话,返回 −1)。
例如,给出这样一个字符串
"racecar"
你的函数应该返回 3,因为对于下标为 3 的字符 e, 其左边相邻的子字符串是 "rac", 而右边相邻的子字符串是 "car"。
注: 与空字符串(长度为 0 的字符串)相反的还是一个空字符串。
假定:
- S 长度范围 [0..2,000,000].
编写一个函数
func Solution(S string) int
从给出的字符串 S 中,找到并返回这样一个字符的下标(下标从 0 开始算), 使得这个字符左边的子字符串,刚好与右边的子字符串相反 (但如果这样的字符不存在的话,返回 −1)。
例如,给出这样一个字符串
"racecar"
你的函数应该返回 3,因为对于下标为 3 的字符 e, 其左边相邻的子字符串是 "rac", 而右边相邻的子字符串是 "car"。
注: 与空字符串(长度为 0 的字符串)相反的还是一个空字符串。
假定:
- S 长度范围 [0..2,000,000].
编写一个函数
class Solution { public int solution(String S); }
从给出的字符串 S 中,找到并返回这样一个字符的下标(下标从 0 开始算), 使得这个字符左边的子字符串,刚好与右边的子字符串相反 (但如果这样的字符不存在的话,返回 −1)。
例如,给出这样一个字符串
"racecar"
你的函数应该返回 3,因为对于下标为 3 的字符 e, 其左边相邻的子字符串是 "rac", 而右边相邻的子字符串是 "car"。
注: 与空字符串(长度为 0 的字符串)相反的还是一个空字符串。
假定:
- S 长度范围 [0..2,000,000].
编写一个函数
class Solution { public int solution(String S); }
从给出的字符串 S 中,找到并返回这样一个字符的下标(下标从 0 开始算), 使得这个字符左边的子字符串,刚好与右边的子字符串相反 (但如果这样的字符不存在的话,返回 −1)。
例如,给出这样一个字符串
"racecar"
你的函数应该返回 3,因为对于下标为 3 的字符 e, 其左边相邻的子字符串是 "rac", 而右边相邻的子字符串是 "car"。
注: 与空字符串(长度为 0 的字符串)相反的还是一个空字符串。
假定:
- S 长度范围 [0..2,000,000].
编写一个函数
function solution(S);
从给出的字符串 S 中,找到并返回这样一个字符的下标(下标从 0 开始算), 使得这个字符左边的子字符串,刚好与右边的子字符串相反 (但如果这样的字符不存在的话,返回 −1)。
例如,给出这样一个字符串
"racecar"
你的函数应该返回 3,因为对于下标为 3 的字符 e, 其左边相邻的子字符串是 "rac", 而右边相邻的子字符串是 "car"。
注: 与空字符串(长度为 0 的字符串)相反的还是一个空字符串。
假定:
- S 长度范围 [0..2,000,000].
编写一个函数
fun solution(S: String): Int
从给出的字符串 S 中,找到并返回这样一个字符的下标(下标从 0 开始算), 使得这个字符左边的子字符串,刚好与右边的子字符串相反 (但如果这样的字符不存在的话,返回 −1)。
例如,给出这样一个字符串
"racecar"
你的函数应该返回 3,因为对于下标为 3 的字符 e, 其左边相邻的子字符串是 "rac", 而右边相邻的子字符串是 "car"。
注: 与空字符串(长度为 0 的字符串)相反的还是一个空字符串。
假定:
- S 长度范围 [0..2,000,000].
编写一个函数
function solution(S)
从给出的字符串 S 中,找到并返回这样一个字符的下标(下标从 0 开始算), 使得这个字符左边的子字符串,刚好与右边的子字符串相反 (但如果这样的字符不存在的话,返回 −1)。
例如,给出这样一个字符串
"racecar"
你的函数应该返回 3,因为对于下标为 3 的字符 e, 其左边相邻的子字符串是 "rac", 而右边相邻的子字符串是 "car"。
注: 与空字符串(长度为 0 的字符串)相反的还是一个空字符串。
假定:
- S 长度范围 [0..2,000,000].
编写一个函数
int solution(NSString *S);
从给出的字符串 S 中,找到并返回这样一个字符的下标(下标从 0 开始算), 使得这个字符左边的子字符串,刚好与右边的子字符串相反 (但如果这样的字符不存在的话,返回 −1)。
例如,给出这样一个字符串
"racecar"
你的函数应该返回 3,因为对于下标为 3 的字符 e, 其左边相邻的子字符串是 "rac", 而右边相邻的子字符串是 "car"。
注: 与空字符串(长度为 0 的字符串)相反的还是一个空字符串。
假定:
- S 长度范围 [0..2,000,000].
编写一个函数
function solution(S: PChar): longint;
从给出的字符串 S 中,找到并返回这样一个字符的下标(下标从 0 开始算), 使得这个字符左边的子字符串,刚好与右边的子字符串相反 (但如果这样的字符不存在的话,返回 −1)。
例如,给出这样一个字符串
"racecar"
你的函数应该返回 3,因为对于下标为 3 的字符 e, 其左边相邻的子字符串是 "rac", 而右边相邻的子字符串是 "car"。
注: 与空字符串(长度为 0 的字符串)相反的还是一个空字符串。
假定:
- S 长度范围 [0..2,000,000].
编写一个函数
function solution($S);
从给出的字符串 S 中,找到并返回这样一个字符的下标(下标从 0 开始算), 使得这个字符左边的子字符串,刚好与右边的子字符串相反 (但如果这样的字符不存在的话,返回 −1)。
例如,给出这样一个字符串
"racecar"
你的函数应该返回 3,因为对于下标为 3 的字符 e, 其左边相邻的子字符串是 "rac", 而右边相邻的子字符串是 "car"。
注: 与空字符串(长度为 0 的字符串)相反的还是一个空字符串。
假定:
- S 长度范围 [0..2,000,000].
编写一个函数
sub solution { my ($S) = @_; ... }
从给出的字符串 S 中,找到并返回这样一个字符的下标(下标从 0 开始算), 使得这个字符左边的子字符串,刚好与右边的子字符串相反 (但如果这样的字符不存在的话,返回 −1)。
例如,给出这样一个字符串
"racecar"
你的函数应该返回 3,因为对于下标为 3 的字符 e, 其左边相邻的子字符串是 "rac", 而右边相邻的子字符串是 "car"。
注: 与空字符串(长度为 0 的字符串)相反的还是一个空字符串。
假定:
- S 长度范围 [0..2,000,000].
编写一个函数
def solution(S)
从给出的字符串 S 中,找到并返回这样一个字符的下标(下标从 0 开始算), 使得这个字符左边的子字符串,刚好与右边的子字符串相反 (但如果这样的字符不存在的话,返回 −1)。
例如,给出这样一个字符串
"racecar"
你的函数应该返回 3,因为对于下标为 3 的字符 e, 其左边相邻的子字符串是 "rac", 而右边相邻的子字符串是 "car"。
注: 与空字符串(长度为 0 的字符串)相反的还是一个空字符串。
假定:
- S 长度范围 [0..2,000,000].
编写一个函数
def solution(s)
从给出的字符串 S 中,找到并返回这样一个字符的下标(下标从 0 开始算), 使得这个字符左边的子字符串,刚好与右边的子字符串相反 (但如果这样的字符不存在的话,返回 −1)。
例如,给出这样一个字符串
"racecar"
你的函数应该返回 3,因为对于下标为 3 的字符 e, 其左边相邻的子字符串是 "rac", 而右边相邻的子字符串是 "car"。
注: 与空字符串(长度为 0 的字符串)相反的还是一个空字符串。
假定:
- S 长度范围 [0..2,000,000].
编写一个函数
object Solution { def solution(s: String): Int }
从给出的字符串 S 中,找到并返回这样一个字符的下标(下标从 0 开始算), 使得这个字符左边的子字符串,刚好与右边的子字符串相反 (但如果这样的字符不存在的话,返回 −1)。
例如,给出这样一个字符串
"racecar"
你的函数应该返回 3,因为对于下标为 3 的字符 e, 其左边相邻的子字符串是 "rac", 而右边相邻的子字符串是 "car"。
注: 与空字符串(长度为 0 的字符串)相反的还是一个空字符串。
假定:
- S 长度范围 [0..2,000,000].
编写一个函数
public func solution(_ S : inout String) -> Int
从给出的字符串 S 中,找到并返回这样一个字符的下标(下标从 0 开始算), 使得这个字符左边的子字符串,刚好与右边的子字符串相反 (但如果这样的字符不存在的话,返回 −1)。
例如,给出这样一个字符串
"racecar"
你的函数应该返回 3,因为对于下标为 3 的字符 e, 其左边相邻的子字符串是 "rac", 而右边相邻的子字符串是 "car"。
注: 与空字符串(长度为 0 的字符串)相反的还是一个空字符串。
假定:
- S 长度范围 [0..2,000,000].
编写一个函数
function solution(S: string): number;
从给出的字符串 S 中,找到并返回这样一个字符的下标(下标从 0 开始算), 使得这个字符左边的子字符串,刚好与右边的子字符串相反 (但如果这样的字符不存在的话,返回 −1)。
例如,给出这样一个字符串
"racecar"
你的函数应该返回 3,因为对于下标为 3 的字符 e, 其左边相邻的子字符串是 "rac", 而右边相邻的子字符串是 "car"。
注: 与空字符串(长度为 0 的字符串)相反的还是一个空字符串。
假定:
- S 长度范围 [0..2,000,000].
编写一个函数
Private Function solution(S As String) As Integer
从给出的字符串 S 中,找到并返回这样一个字符的下标(下标从 0 开始算), 使得这个字符左边的子字符串,刚好与右边的子字符串相反 (但如果这样的字符不存在的话,返回 −1)。
例如,给出这样一个字符串
"racecar"
你的函数应该返回 3,因为对于下标为 3 的字符 e, 其左边相邻的子字符串是 "rac", 而右边相邻的子字符串是 "car"。
注: 与空字符串(长度为 0 的字符串)相反的还是一个空字符串。
假定:
- S 长度范围 [0..2,000,000].
Write a function:
int solution(char *S);
that, given a string S, returns the index (counting from 0) of a character such that the part of the string to the left of that character is a reversal of the part of the string to its right. The function should return −1 if no such index exists.
Note: reversing an empty string (i.e. a string whose length is zero) gives an empty string.
For example, given a string:
"racecar"
the function should return 3, because the substring to the left of the character "e" at index 3 is "rac", and the one to the right is "car".
Given a string:
"x"
the function should return 0, because both substrings are empty.
Write an efficient algorithm for the following assumptions:
- the length of string S is within the range [0..2,000,000].
Write a function:
int solution(string &S);
that, given a string S, returns the index (counting from 0) of a character such that the part of the string to the left of that character is a reversal of the part of the string to its right. The function should return −1 if no such index exists.
Note: reversing an empty string (i.e. a string whose length is zero) gives an empty string.
For example, given a string:
"racecar"
the function should return 3, because the substring to the left of the character "e" at index 3 is "rac", and the one to the right is "car".
Given a string:
"x"
the function should return 0, because both substrings are empty.
Write an efficient algorithm for the following assumptions:
- the length of string S is within the range [0..2,000,000].
Write a function:
int solution(string &S);
that, given a string S, returns the index (counting from 0) of a character such that the part of the string to the left of that character is a reversal of the part of the string to its right. The function should return −1 if no such index exists.
Note: reversing an empty string (i.e. a string whose length is zero) gives an empty string.
For example, given a string:
"racecar"
the function should return 3, because the substring to the left of the character "e" at index 3 is "rac", and the one to the right is "car".
Given a string:
"x"
the function should return 0, because both substrings are empty.
Write an efficient algorithm for the following assumptions:
- the length of string S is within the range [0..2,000,000].
Write a function:
class Solution { public int solution(string S); }
that, given a string S, returns the index (counting from 0) of a character such that the part of the string to the left of that character is a reversal of the part of the string to its right. The function should return −1 if no such index exists.
Note: reversing an empty string (i.e. a string whose length is zero) gives an empty string.
For example, given a string:
"racecar"
the function should return 3, because the substring to the left of the character "e" at index 3 is "rac", and the one to the right is "car".
Given a string:
"x"
the function should return 0, because both substrings are empty.
Write an efficient algorithm for the following assumptions:
- the length of string S is within the range [0..2,000,000].
Write a function:
int solution(String S);
that, given a string S, returns the index (counting from 0) of a character such that the part of the string to the left of that character is a reversal of the part of the string to its right. The function should return −1 if no such index exists.
Note: reversing an empty string (i.e. a string whose length is zero) gives an empty string.
For example, given a string:
"racecar"
the function should return 3, because the substring to the left of the character "e" at index 3 is "rac", and the one to the right is "car".
Given a string:
"x"
the function should return 0, because both substrings are empty.
Write an efficient algorithm for the following assumptions:
- the length of string S is within the range [0..2,000,000].
Write a function:
func Solution(S string) int
that, given a string S, returns the index (counting from 0) of a character such that the part of the string to the left of that character is a reversal of the part of the string to its right. The function should return −1 if no such index exists.
Note: reversing an empty string (i.e. a string whose length is zero) gives an empty string.
For example, given a string:
"racecar"
the function should return 3, because the substring to the left of the character "e" at index 3 is "rac", and the one to the right is "car".
Given a string:
"x"
the function should return 0, because both substrings are empty.
Write an efficient algorithm for the following assumptions:
- the length of string S is within the range [0..2,000,000].
Write a function:
class Solution { public int solution(String S); }
that, given a string S, returns the index (counting from 0) of a character such that the part of the string to the left of that character is a reversal of the part of the string to its right. The function should return −1 if no such index exists.
Note: reversing an empty string (i.e. a string whose length is zero) gives an empty string.
For example, given a string:
"racecar"
the function should return 3, because the substring to the left of the character "e" at index 3 is "rac", and the one to the right is "car".
Given a string:
"x"
the function should return 0, because both substrings are empty.
Write an efficient algorithm for the following assumptions:
- the length of string S is within the range [0..2,000,000].
Write a function:
class Solution { public int solution(String S); }
that, given a string S, returns the index (counting from 0) of a character such that the part of the string to the left of that character is a reversal of the part of the string to its right. The function should return −1 if no such index exists.
Note: reversing an empty string (i.e. a string whose length is zero) gives an empty string.
For example, given a string:
"racecar"
the function should return 3, because the substring to the left of the character "e" at index 3 is "rac", and the one to the right is "car".
Given a string:
"x"
the function should return 0, because both substrings are empty.
Write an efficient algorithm for the following assumptions:
- the length of string S is within the range [0..2,000,000].
Write a function:
function solution(S);
that, given a string S, returns the index (counting from 0) of a character such that the part of the string to the left of that character is a reversal of the part of the string to its right. The function should return −1 if no such index exists.
Note: reversing an empty string (i.e. a string whose length is zero) gives an empty string.
For example, given a string:
"racecar"
the function should return 3, because the substring to the left of the character "e" at index 3 is "rac", and the one to the right is "car".
Given a string:
"x"
the function should return 0, because both substrings are empty.
Write an efficient algorithm for the following assumptions:
- the length of string S is within the range [0..2,000,000].
Write a function:
fun solution(S: String): Int
that, given a string S, returns the index (counting from 0) of a character such that the part of the string to the left of that character is a reversal of the part of the string to its right. The function should return −1 if no such index exists.
Note: reversing an empty string (i.e. a string whose length is zero) gives an empty string.
For example, given a string:
"racecar"
the function should return 3, because the substring to the left of the character "e" at index 3 is "rac", and the one to the right is "car".
Given a string:
"x"
the function should return 0, because both substrings are empty.
Write an efficient algorithm for the following assumptions:
- the length of string S is within the range [0..2,000,000].
Write a function:
function solution(S)
that, given a string S, returns the index (counting from 0) of a character such that the part of the string to the left of that character is a reversal of the part of the string to its right. The function should return −1 if no such index exists.
Note: reversing an empty string (i.e. a string whose length is zero) gives an empty string.
For example, given a string:
"racecar"
the function should return 3, because the substring to the left of the character "e" at index 3 is "rac", and the one to the right is "car".
Given a string:
"x"
the function should return 0, because both substrings are empty.
Write an efficient algorithm for the following assumptions:
- the length of string S is within the range [0..2,000,000].
Write a function:
int solution(NSString *S);
that, given a string S, returns the index (counting from 0) of a character such that the part of the string to the left of that character is a reversal of the part of the string to its right. The function should return −1 if no such index exists.
Note: reversing an empty string (i.e. a string whose length is zero) gives an empty string.
For example, given a string:
"racecar"
the function should return 3, because the substring to the left of the character "e" at index 3 is "rac", and the one to the right is "car".
Given a string:
"x"
the function should return 0, because both substrings are empty.
Write an efficient algorithm for the following assumptions:
- the length of string S is within the range [0..2,000,000].
Write a function:
function solution(S: PChar): longint;
that, given a string S, returns the index (counting from 0) of a character such that the part of the string to the left of that character is a reversal of the part of the string to its right. The function should return −1 if no such index exists.
Note: reversing an empty string (i.e. a string whose length is zero) gives an empty string.
For example, given a string:
"racecar"
the function should return 3, because the substring to the left of the character "e" at index 3 is "rac", and the one to the right is "car".
Given a string:
"x"
the function should return 0, because both substrings are empty.
Write an efficient algorithm for the following assumptions:
- the length of string S is within the range [0..2,000,000].
Write a function:
function solution($S);
that, given a string S, returns the index (counting from 0) of a character such that the part of the string to the left of that character is a reversal of the part of the string to its right. The function should return −1 if no such index exists.
Note: reversing an empty string (i.e. a string whose length is zero) gives an empty string.
For example, given a string:
"racecar"
the function should return 3, because the substring to the left of the character "e" at index 3 is "rac", and the one to the right is "car".
Given a string:
"x"
the function should return 0, because both substrings are empty.
Write an efficient algorithm for the following assumptions:
- the length of string S is within the range [0..2,000,000].
Write a function:
sub solution { my ($S) = @_; ... }
that, given a string S, returns the index (counting from 0) of a character such that the part of the string to the left of that character is a reversal of the part of the string to its right. The function should return −1 if no such index exists.
Note: reversing an empty string (i.e. a string whose length is zero) gives an empty string.
For example, given a string:
"racecar"
the function should return 3, because the substring to the left of the character "e" at index 3 is "rac", and the one to the right is "car".
Given a string:
"x"
the function should return 0, because both substrings are empty.
Write an efficient algorithm for the following assumptions:
- the length of string S is within the range [0..2,000,000].
Write a function:
def solution(S)
that, given a string S, returns the index (counting from 0) of a character such that the part of the string to the left of that character is a reversal of the part of the string to its right. The function should return −1 if no such index exists.
Note: reversing an empty string (i.e. a string whose length is zero) gives an empty string.
For example, given a string:
"racecar"
the function should return 3, because the substring to the left of the character "e" at index 3 is "rac", and the one to the right is "car".
Given a string:
"x"
the function should return 0, because both substrings are empty.
Write an efficient algorithm for the following assumptions:
- the length of string S is within the range [0..2,000,000].
Write a function:
def solution(s)
that, given a string S, returns the index (counting from 0) of a character such that the part of the string to the left of that character is a reversal of the part of the string to its right. The function should return −1 if no such index exists.
Note: reversing an empty string (i.e. a string whose length is zero) gives an empty string.
For example, given a string:
"racecar"
the function should return 3, because the substring to the left of the character "e" at index 3 is "rac", and the one to the right is "car".
Given a string:
"x"
the function should return 0, because both substrings are empty.
Write an efficient algorithm for the following assumptions:
- the length of string S is within the range [0..2,000,000].
Write a function:
object Solution { def solution(s: String): Int }
that, given a string S, returns the index (counting from 0) of a character such that the part of the string to the left of that character is a reversal of the part of the string to its right. The function should return −1 if no such index exists.
Note: reversing an empty string (i.e. a string whose length is zero) gives an empty string.
For example, given a string:
"racecar"
the function should return 3, because the substring to the left of the character "e" at index 3 is "rac", and the one to the right is "car".
Given a string:
"x"
the function should return 0, because both substrings are empty.
Write an efficient algorithm for the following assumptions:
- the length of string S is within the range [0..2,000,000].
Write a function:
public func solution(_ S : inout String) -> Int
that, given a string S, returns the index (counting from 0) of a character such that the part of the string to the left of that character is a reversal of the part of the string to its right. The function should return −1 if no such index exists.
Note: reversing an empty string (i.e. a string whose length is zero) gives an empty string.
For example, given a string:
"racecar"
the function should return 3, because the substring to the left of the character "e" at index 3 is "rac", and the one to the right is "car".
Given a string:
"x"
the function should return 0, because both substrings are empty.
Write an efficient algorithm for the following assumptions:
- the length of string S is within the range [0..2,000,000].
Write a function:
function solution(S: string): number;
that, given a string S, returns the index (counting from 0) of a character such that the part of the string to the left of that character is a reversal of the part of the string to its right. The function should return −1 if no such index exists.
Note: reversing an empty string (i.e. a string whose length is zero) gives an empty string.
For example, given a string:
"racecar"
the function should return 3, because the substring to the left of the character "e" at index 3 is "rac", and the one to the right is "car".
Given a string:
"x"
the function should return 0, because both substrings are empty.
Write an efficient algorithm for the following assumptions:
- the length of string S is within the range [0..2,000,000].
Write a function:
Private Function solution(S As String) As Integer
that, given a string S, returns the index (counting from 0) of a character such that the part of the string to the left of that character is a reversal of the part of the string to its right. The function should return −1 if no such index exists.
Note: reversing an empty string (i.e. a string whose length is zero) gives an empty string.
For example, given a string:
"racecar"
the function should return 3, because the substring to the left of the character "e" at index 3 is "rac", and the one to the right is "car".
Given a string:
"x"
the function should return 0, because both substrings are empty.
Write an efficient algorithm for the following assumptions:
- the length of string S is within the range [0..2,000,000].