✅💯🔥Simple Code📌🚀| 🔥✔️Easy to understand🎯 | 🎓🧠Beginner friendly🔥| O(logN) TimeComplexity💀💯
Tuntun Mosi ko Pranam\nSolution tuntun mosi ki photo ke baad hai. Scroll Down\n\n# Code\njava []\nclass MedianFinder {\n    PriorityQueue<Integer> pq1;\n    Pri
# Tuntun Mosi ko Pranam\nSolution tuntun mosi ki photo ke baad hai. Scroll Down\n![fd9d3417-20fb-4e19-98fa-3dd39eeedf43_1723794694.932518.png](https://assets.leetcode.com/users/images/a492c0ef-bde0-4447-81e6-2ded326cd877_1724187540.6168394.png)\n# Code\n```java []\nclass MedianFinder {\n    PriorityQueue<Integer> pq1;\n    PriorityQueue<Integer> pq2;\n    public MedianFinder() {\n        this.pq1=new PriorityQueue<Integer>(Collections.reverseOrder());\n        this.pq2=new PriorityQueue<Integer>();\n    }\n    \n    public void addNum(int num) {\n        if(pq1.isEmpty()||pq1.peek()>=num){\n            pq1.add(num);\n        }else{\n            pq2.add(num);\n        }\n\n        if(pq1.size()-pq2.size()>1){\n            pq2.add(pq1.remove());\n        }else if(pq2.size()-pq1.size()>=1){\n            pq1.add(pq2.remove());\n        }\n    }\n    \n    public double findMedian() {\n        if(pq1.size()>pq2.size()){\n            return(double) pq1.peek();\n        }\n        return ((double)pq1.peek()+(double)pq2.peek())/(double)2;\n    }\n}\n\n/**\n * Your MedianFinder object will be instantiated and called as such:\n * MedianFinder obj = new MedianFinder();\n * obj.addNum(num);\n * double param_2 = obj.findMedian();\n */\n```\n![7be995b4-0cf4-4fa3-b48b-8086738ea4ba_1699897744.9062278.jpeg](https://assets.leetcode.com/users/images/fe5117c9-43b1-4ec8-8979-20c4c7f78d98_1721303757.4674635.jpeg)
['Two Pointers', 'Design', 'C', 'Sorting', 'Heap (Priority Queue)', 'Data Stream', 'Python', 'C++', 'Java', 'JavaScript']