publicclassLinkedListPalindrome{publicintisPalindrome(ListNoderoot){// If no Node, false alwaysif(root==null)return0;// If single Node only, true alwaysif(root.next==null)return1;ListNodecurr=root;//1. Find the middle NodeListNodemidNode=findMidNode(curr);//2. Reverse the latter half of listListNoderevNode=reverseNodeList(midNode);//3. Compare each node curr=root;while(curr!=null&&revNode!=null){if(curr.val!=revNode.val){return0;}curr=curr.next;revNode=revNode.next;}return1;}
find the middle node
If list size is even , middle Node will be len/2 th Node
If list size is odd, middle Node will be len/2 th Node(floor Node)
/**
* Use 2 pointer approach
* fast pointer nad slow pointer
*/privateListNodefindMidNode(ListNoderoot){ListNodesp=root;ListNodefp=root;while(fp.next!=null&&fp.next.next!=null){fp=fp.next.next;sp=sp.next;}returnsp;}
ACI.dev’s open-source tool-use platform and Unified MCP Server turns 600+ functions into two simple MCP tools on one server—search and execute. Comes with multi-tenant auth and natural-language permission scopes. 100% open-source under Apache 2.0.
We’ve quietly evolved from a time-series database into the modern PostgreSQL for today’s and tomorrow’s computing, built for performance, scale, and the agentic future.
So we’re changing our name: from Timescale to TigerData. Not to change who we are, but to reflect who we’ve become. TigerData is bold, fast, and built to power the next era of software.
Delve into a trove of insights in this thoughtful post, celebrated by the welcoming DEV Community. Programmers of every stripe are invited to share their viewpoints and enrich our collective expertise.
A simple “thank you” can brighten someone’s day—drop yours in the comments below!
On DEV, exchanging knowledge lightens our path and forges deeper connections. Found this valuable? A quick note of gratitude to the author can make all the difference.
Top comments (0)