
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
A strictly increasing linked list in Python
Suppose we have head of a singly linked list, we have to check whether the values of the nodes are sorted in a strictly ascending order or not.
So, if the input is like [2,61,105,157], then the output will be True.
To solve this, we will follow these steps −
Define a function solve() . This will take head
if head.next is null, then
return True
if head.val >= head.next.val, then
return False
return solve(head.next)
Let us see the following implementation to get better understanding −
Example
class ListNode: def __init__(self, data, next = None): self.val = data self.next = next def make_list(elements): head = ListNode(elements[0]) for element in elements[1:]: ptr = head while ptr.next: ptr = ptr.next ptr.next = ListNode(element) return head class Solution: def solve(self, head): if head.next == None: return True if head.val >= head.next.val: return False return self.solve(head.next) ob = Solution() head = make_list([2,61,105,157]) print(ob.solve(head))
Input
[2,61,105,157]
Output
True
- Related Articles
- Check if list is strictly increasing in Python
- Program to check whether list is strictly increasing or strictly decreasing in Python
- Find groups of strictly increasing numbers in a list in Python
- Strictly increasing sequence JavaScript
- Make Array Strictly Increasing in C++
- Count Strictly Increasing Subarrays in C++
- Program to find length of contiguous strictly increasing sublist in Python
- Strictly increasing or decreasing array - JavaScript
- Find Maximum Sum Strictly Increasing Subarray in C++
- Program to count n digit integers where digits are strictly increasing in Python
- Program to find length of longest strictly increasing then decreasing sublist in Python
- Print all n-digit strictly increasing numbers in C++
- Length of a Linked List in Python
- Program to find length of longest contiguously strictly increasing sublist after removal in Python
- Program to find number of strictly increasing colorful candle sequences are there in Python

Advertisements