Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to write code to realize the longest palindromic subsequence of a string

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the knowledge of "how to write code to achieve the longest return subsequence of a string". Many people will encounter such a dilemma in the operation of actual cases. next, let the editor lead you to learn how to deal with these situations! I hope you can read it carefully and be able to achieve something!

Import java.util.Arrays;/** * @ author pxu * @ create 2021-4-7-5:57 p.m. * / public class Nc154 {public int longestPalindromeSubSeq (String s) {int n = s.length () During the for loop, the data in dp [j] represents the length of the longest palindrome sequence in the substring of s from I to j * after the end of for operation, the data in dp [j] represents the length of the longest palindrome sequence in the substring of s from 0 to j, so the final result returned by the program is the value of DP [n-1]. * / int [] dp = new int [n]; / * is filled with 1 because each character is a palindromic string of length 1 * / Arrays.fill (dp,1); for (int I = nMuth2sidi > = 0 IMel -) {/ * pre always represents the length of the longest palindrome sequence in the substring of the string s from iMel 1 to JMUI 1, so its initial value is set to 0 * / int pre=0; for (int Jubi iSidsj)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report