[C#] LeetCode 5. Longest Palindromic Substring

Given a string s, return the longest palindromic substring in s.

Example 1:

Input: s = "babad"
Output: "bab"
Note: "aba" is also a valid answer.
Example 2:

Input: s = "cbbd"
Output: "bb"
Example 3:

Input: s = "a"
Output: "a"
Example 4:

Input: s = "ac"
Output: "a"

Constraints:

1 <= s.length <= 1000
s consist of only digits and English letters (lower-case and/or upper-case)

public class Solution
{
	public string LongestPalindrome(string s){
		if(String.IsNullOrEmpty(s)){
			return s;
		}
		string longest=s.Substring(0,1);
		for(int i=0;i<s.Length;++i){
			string temp = used(s,i,i);
			if(temp.Length>longest.Length){
				longest = temp;
			}
			temp=used(s,i,i+1);
			if(temp.Length>longest.Length){
				longest = temp;
			}
		}
		return longest;
	}
	public string used(string s, int star, int end){
		while(star>=0&&end<s.Length&&s[star]==s[end]){
			--star;
			++end;
		}
		return s.Substring(star+1,end-star-1);
	}
}

https://ithelp.ithome.com.tw/upload/images/20210108/20132436ScCXLOcZoP.jpg


<<:  MySQL 逻辑及运算子类型资料之基本操作

>>:  iOS APP 开发 OC 第十五天,网路请求(请求方式对比,缓存策略,请求时长)

Day23 X WebAssembly

也许你早就听过 WebAssembly 这个词,传说中它可以让 C, C++, Rust 等系统语...

[DAY17] 介绍 Azure Machine Learning SDK

DAY17 介绍 Azure Machine Learning SDK 我们前面一半的课程,学习了透...

[重构倒数第27天] - 在 Vue 各种 CSS 的引入使用

前言 该系列是为了让看过Vue官方文件或学过Vue但是却不知道怎麽下手去重构现在有的网站而去规画的系...

AutoML NAS - SGAS: Sequential Greedy Architecture Search(上篇)

1 前言 近年来深度学习使用在许多比赛中,但几乎都使用ensemble(集成)的方式或是使用庞大的模...

Day 19 - 网页元素DOM - 表单元件的Event,表单的type 设定

制作表单 createRadio(); 沿用上一个文章的参考 加上以下设定 我们可以用radio去做...