Comments (6)
@kq58 you can contribute adding the correct algorithm.
from algorithms.
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 you can contribute adding the correct algorithm.
@ericklarac i'm a beginner too. i'll try my best.
from algorithms.
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.
@ericklarac my internet sucks when viewing github or any other out_wall sites. i'll try to add some mline coments.
from algorithms.
@kq58 no worries, I will merge for now.
from algorithms.
Related Issues (20)
- Add algorithm for calculating the shortest path for planting trees left along a road at equal distances from eachother using dp.
- maintainer needed HOT 1
- Migrate Travis
- search_range code needs a slight fix. it does not work for certain conditions HOT 3
- Algorithms
- Algorithm
- Feature suggestion "A simple way to add test cases"
- Modify docs/source
- Views of Binary Tree HOT 5
- Fix TODO in `polynomial.py`
- Add A* pathfinding algorithm HOT 2
- Fix Todo add dynamic programming algorithm to min_distance
- Add `validate_bst` function HOT 1
- Add `Fast Fourier Transform` in maths HOT 1
- Add `Linear Regression` HOT 5
- Add Kadane's Algorithm
- Add count_paths DP, recursive, name change of existing HOT 2
- Missing `f` prefix on f-strings
- Math Series
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from algorithms.