Giter VIP home page Giter VIP logo

Comments (6)

ericklarac avatar ericklarac commented on May 30, 2024

@kq58 you can contribute adding the correct algorithm.

from algorithms.

kq58 avatar kq58 commented on May 30, 2024

this could be an implementation of lps. it can return the logestSubStr as well.you can remove the '#' in the last line to do it.

longest_palindromic_subsequence.py
def longest_palindromic_subsequence(s):

    k = len(s)
    olist = [0] * k    # 申请长度为n的列表,并初始化
    nList = [0] * k    # 同上
    logestSubStr = ""
    logestLen = 0

    for j in range(0, k):
        for i in range(0, j + 1):
            if j - i <= 1:
                if s[i] == s[j]:
                    nList[i] = 1                 # 当 j 时,第 i 个子串为回文子串
                    len_t = j - i + 1
                    if logestLen < len_t:        # 判断长度
                        logestSubStr = s[i:j + 1]
                        logestLen = len_t
            else:
                if s[i] == s[j] and olist[i+1]:   # 当j-i>1时,判断s[i]是否等于s[j],并判断当j-1时,第i+1个子串是否为回文子串
                    nList[i] = 1                  # 当 j 时,第 i 个子串为回文子串
                    len_t = j - i + 1
                    if logestLen < len_t:
                        logestSubStr = s[i:j + 1]
                        logestLen = len_t
        olist = nList                            # 覆盖旧的列表
        nList = [0] * k                          # 新的列表清空
    # ~ from icecream import ic
    # ~ ic(s, logestSubStr)
    return logestLen#, logestSubStr

from algorithms.

kq58 avatar kq58 commented on May 30, 2024

@kq58 you can contribute adding the correct algorithm.

@ericklarac i'm a beginner too. i'll try my best.

from algorithms.

ericklarac avatar ericklarac commented on May 30, 2024

Here's the right place to learn, check how to create PR on Github.

Then add your algorithm, and consider adding test cases.

from algorithms.

kq58 avatar kq58 commented on May 30, 2024

@ericklarac my internet sucks when viewing github or any other out_wall sites. i'll try to add some mline coments.

from algorithms.

ericklarac avatar ericklarac commented on May 30, 2024

@kq58 no worries, I will merge for now.

from algorithms.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.