/**
* Problem: LeetCode 3884 - First Matching Character From Both Ends
* Difficulty: Easy
* Language: Java
* Author: CodeByTushu
*/
class Solution {
public int firstMatchingIndex(String s) {
int n = s.length();
for (int i = 0; i < n; i++) {
if (s.charAt(i) == s.charAt(n - i - 1)) {
return i;
}
}
return -1;
}
}
"""
Problem: LeetCode 3884 - First Matching Character From Both Ends
Difficulty: Easy
Language: Python 3
Author: CodeByTushu
"""
class Solution:
def firstMatchingIndex(self, s: str) -> int:
n = len(s)
for i in range(n):
if s[i] == s[n - i - 1]:
return i
return -1
/**
* Problem: LeetCode 3884 - First Matching Character From Both Ends
* Difficulty: Easy
* Language: C++
* Author: CodeByTushu
*/
#include <string>
using namespace std;
class Solution {
public:
int firstMatchingIndex(string s) {
int n = static_cast<int>(s.size());
for (int i = 0; i < n; i++) {
if (s[i] == s[n - i - 1]) {
return i;
}
}
return -1;
}
};
/**
* Problem: LeetCode 3884 - First Matching Character From Both Ends
* Difficulty: Easy
* Language: JavaScript
* Author: CodeByTushu
*/
/**
* @param {string} s
* @return {number}
*/
var firstMatchingIndex = function(s) {
const n = s.length;
for (let i = 0; i < n; i++) {
if (s[i] === s[n - i - 1]) {
return i;
}
}
return -1;
};