リンクを新しいタブで開く
    • 作業報告
    • メール
    • リライト
    • スピーチ
    • タイトル ジェネレーター
    • スマート返信
    • エッセイ
    • ジョーク
    • Instagram 投稿
    • X 投稿
    • Facebook 投稿
    • ストーリー
    • 添え状
    • 履歴書
    • 職務明細書
    • 推薦状
    • 退職願
    • 招待状
    • グリーティング メッセージ
    • その他のテンプレートを試します
    フィードバック
    ありがとうございました!詳細をお聞かせください
  1. Finding the longest palindromic substring means identifying the longest contiguous sequence in a string that reads the same forwards and backwards. This is different from the longest palindromic subsequence, which does not require characters to be contiguous.

    Expand Around Center Approach (O(n²) Time)

    This is one of the most efficient and straightforward methods for this problem.

    Steps:

    1. Iterate through each character in the string, treating it as a potential palindrome center.

    2. Expand outwards for both odd-length and even-length palindromes.

    3. Track the longest palindrome found during expansion.

    Code Example:

    function longestPalindrome(s) {
    if (!s || s.length < 1) return "";
    let start = 0, end = 0;

    for (let i = 0; i < s.length; i++) {
    let len1 = expandFromCenter(s, i, i); // Odd length
    let len2 = expandFromCenter(s, i, i + 1); // Even length
    let len = Math.max(len1, len2);
    if (len > end - start) {
    start = i - Math.floor((len - 1) / 2);
    end = i + Math.floor(len / 2);
    }
    }
    return s.substring(start, end + 1);
    }

    function expandFromCenter(str, left, right) {
    while (left >= 0 && right < str.length && str[left] === str[right]) {
    left--;
    right++;
    }
    return right - left - 1;
    }

    // Example usage:
    console.log(longestPalindrome("babad")); // "bab" or "aba"
    console.log(longestPalindrome("cbbd")); // "bb"
    コピーしました。
    フィードバック
    ありがとうございました!詳細をお聞かせください
  2. Longest Palindromic Substring - LeetCode

    Longest Palindromic Substring - Given a string s, return the longest palindromic substring in s. Example 1: Input: s = "babad" Output: "bab" Explanation: "aba" is …

  3. The Longest Palindromic Substring in JavaScript

    2024年2月26日 · Explore the 'Longest Palindromic Substring' problem: its relevance in web development and four JavaScript (ES6 & TypeScript) solutions for efficiency.

    • 推定読み取り時間:6 分
    • JavaScript: The longest palindrome in a specified string

      2025年2月28日 · Write a JavaScript function that computes the longest palindromic substring in a string using nested loops for comparison. Write a …

    • javascript - Finding Longest Palindromic Substring - Stack ...

      2023年9月2日 · You can optimize the code and avoid running into memory errors, by implementing a more efficient algorithm, such as Manacher's algorithm. Manacher's algorithm is designed specifically …

      • レビュー数: 1
      • Longest Palindromic Substring: JavaScript - DEV Community

        2022年4月13日 · Both of these strings contain palindromic substrings 'oo'. Find the longest set of characters in a string that is a palindrome, or the 'longest palindromic substring'. There are a few …

      • Longest Palindromic Substring - LeetCode javascript solutions

        Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. Example 1: Input: "babad" Output: "bab" Note: "aba" is also a valid answer. Example 2: …

      • Longest Palindromic Substring - JavaScript Coding Challenge ...

        Longest Palindromic Substring - JavaScript: Explore the JavaScript approach to finding the longest palindromic substring. View practical examples and explanations.

      • Longest Palindromic Substring - GeeksforGeeks

        2025年10月3日 · Generate all possible substrings of the given string. For each substring, check if it is a palindrome. If it is, update the result if its length is greater than the longest palindrome found so far.

      • Discovering the Longest Palindromic Substring in …

        2024年4月26日 · In this guide, I will show you how to efficiently find the longest palindromic substring within a given string. The longest palindromic substring …

      このサイトを利用すると、分析、カスタマイズされたコンテンツ、広告に Cookie を使用することに同意したことになります。サード パーティの Cookie に関する詳細情報|Microsoft のプライバシー ポリシー