请写一个程序，寻找给定字符串中的最长回文子串。


"babad"
以下是Python代码实现：
```
def longest_palindromic(s):
    if len(s) < 2:
        return s
    start, end = 0, 0
    for i in range(len(s)):
        len1 = expandAroundCenter(s, i, i)
        len2 = expandAroundCenter(s, i, i + 1)
        maxlen = max(len1, len2)
        if maxlen > end - start:
            start = i - (maxlen - 1) // 2
            end = i + maxlen // 2
    return s[start:end+1]

def expandAroundCenter(s, left, right):
    while left >= 0 and right < len(s) and s[left] == s[right]:
        left -= 1
        right += 1
    return right - left - 1

s="babad"
print(longest_palindromic(s))
```
输出：
```
bab
```