Minimum Insertion Steps to Make a String Palindrome - LeetCode 1312 - Python Solution
Solution Blog: (sign into leetcode to view)
- https://leetcode.com/problems/minimum-insertion-steps-to-make-a-string-palindrome/solutions/3445311/intuitive-python-solution-solution-blog/
Use 2 pointers.
left pointer that starts @ index 0
right pointer that starts @ last index
If they point to the same value - move pointers inward.
If they don't add 1 and take the minimum of the two possible paths:
increment left pointer by 1
decrement right pointer by 1
When the left pointer passes the right pointer you've finished processing so return 0.
Time complexity: O(N^2)
Space complexity: O(N^2)
Hope this helped! Have an awesome day!
#python #leetcode #tutorial
Видео Minimum Insertion Steps to Make a String Palindrome - LeetCode 1312 - Python Solution автора Питоновый старт для знатоков
Видео Minimum Insertion Steps to Make a String Palindrome - LeetCode 1312 - Python Solution автора Питоновый старт для знатоков
Информация
2 декабря 2023 г. 5:38:42
00:07:25
Похожие видео