Code Issues Pull requests Discussions Ruby implementation of Algorithms,Data-structures and programming challenges algorithmstackleetcodequicksorthackerrankbubble-sortinsertion-sortleetcode-solutionsbinary-searchcodilitymerge-sortpythagorean-tripleskadanes-algorithmarray-rotationknuth-shuffling-algorithmdutch-nationalflag...
Level Averages in a Binary Tree, Minimum Depth of a Binary Tree, Level Order Successor, Connect Level Order Siblings, etc. 🎭 PsuendoCode Tree Depth First Search Pattern 🌲 Stack< Tree Node stack = new Stack<>(); stack.push(root); while (!stack.isEmpty()) { TreeNode currentNode...
Note: You are not suppose to use the library’s sort function for this problem. Example: Input: [2,0,2,1,1,0] Output: [0,0,1,1,2,2] 1. 2. Follow up: A rather straight forward solution is a two-pass algorithm using counting sort. First, iterate the array count...
Memory Limit: 65536/65536 K (Java/Others) Problem Description P is a permutation of the integers from 1 to N(index starting from 1). Here is the code of Bubble Sort in C++. for(int i=1;i<=N;++i) for(int j=N,t;j>i;—j) if(P[j-1] > P[j]) t=P[j],P[j]=P[j-1]...
[LeetCode] Sort Characters By Frequency 根据字符出现频率排序 Given a string, sort it in decreasing order based on the frequency of characters. Example 1: Input: "tree" Output: "eert" Explanation: 'e' appears twice while 'r' and 't' both appear once. So 'e' must appear before both '...
sub-problem is to find mid index of current array and divide it into two. post-order process, merge the two sorted array into one sorted array. Time complexity: O(n) for divide process, O(nlogn) for merge. Space complexity: call stack O(logn), additional cost O(n) -- for helper ...
Here's a list of 30 coding interview patterns, each with one or two example LeetCode problems:1. Sliding WindowProblem 1: Minimum Size Subarray Sum Problem 2: Longest Substring Without Repeating Characters2. Two PointersProblem 1: 3Sum Problem 2: Container With Most Water...
Python 的实现在 lintcode 上会提示 TLE, leetcode 上勉强通过,这里需要注意的是采用if A is not None:的效率要比if A:高,不然 leetcode 上也过不了。具体原因可参考Stack Overflow上的讨论。 复杂度分析 最好情况:原链表已经逆序,每得到一个新节点仅需要一次比较, 时间复杂度为O(n), 使用了 dummy 和 ...
Lintcode:TopologicalSorting 这道题参考了网上一些很好的思路: method1: Record the pre nodes of every node, then find out a node without pre node in each iteration and delete this node from unvisi DFS Graph Lintcode Topological Sort i++ ...
javasort我们在这篇文章中对所有的容器类的实现类和数组的sort方法进行分析,它们分别是:1)collection: ArrayList,LinkedLsit,Vector,Stack TreeSet,HashSet,LinkedHashSetMap: HashMap,LinkedHashMap,WeakHashMap, TreeMap, HashTable, Ide java vector倒序 ...