Leetcode 314: Binary Tree Vertical Order Traversal

314. Binary Tree Vertical Order Traversal  Total Accepted: 13025 Total Submissions: 38434 Difficulty: Medium Contributors: Admin Given a binary tree, return the vertical order traversal of its nodes’ values. (ie, from top to bottom, column by column). If two nodes are in the same row and column, the order should be from left to right. …

Leetcode 155: Min Stack

155. Min Stack Total Accepted: 96784 Total Submissions: 383098 Difficulty: Easy Contributors: Admin Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. push(x) — Push element x onto stack. pop() — Removes the element on top of the stack. top() — Get the top element. getMin() — Retrieve …

Finding missing k numbers in 0…N-1

This is the interview question from http://stackoverflow.com/questions/3492302/easy-interview-question-got-harder-given-numbers-1-100-find-the-missing-numbe?rq=1: You are given a bag of numbers which are 0 ~ N-1 integers except k numbers. Return the k missing numbers. The solution should operate in O(N) time complexity and O(k) space complexity. Although the highest voted post uses some theorem to solve the question, I would like to …

Leetcode 311: Sparse Matrix Multiplication

311. Sparse Matrix Multiplication Total Accepted: 13356 Total Submissions: 26970 Difficulty: Medium Contributors: Admin Given two sparse matrices A and B, return the result of AB. You may assume that A‘s column number is equal to B‘s row number.   Code from collections import defaultdict class Solution(object): def multiply(self, A, B): “”” :type A: List[List[int]] …

Leetcode 237: Delete Node in a Linked List

237. Delete Node in a Linked List Total Accepted: 114749 Total Submissions: 255293 Difficulty: Easy Contributors: Admin Write a function to delete a node (except the tail) in a singly linked list, given only access to that node. Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the …

Leetcode 117: Populating Next Right Pointers in Each Node II

117. Populating Next Right Pointers in Each Node II  Total Accepted: 74952 Total Submissions: 225622 Difficulty: Hard Contributors: Admin Follow up for problem “Populating Next Right Pointers in Each Node“. What if the given tree could be any binary tree? Would your previous solution still work? Note: You may only use constant extra space. For …

Leetcode 371: Sum of Two Integers

371. Sum of Two Integers  Total Accepted: 42501 Total Submissions: 82322 Difficulty: Easy Contributors: Admin Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Example:Given a = 1 and b = 2, return 3.   Code class Solution(object): def getSum(self, a, b): “”” …

Leetcode 137: Single Number II

137. Single Number II Total Accepted: 100365 Total Submissions: 253451 Difficulty: Medium Contributors: Admin Given an array of integers, every element appears three times except for one. Find that single one. Note:Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?   Code class Solution(object): def singleNumber(self, nums): “”” …

Leetcode 72: Edit Distance

72. Edit Distance Total Accepted: 71110 Total Submissions: 236049 Difficulty: Hard Contributors: Admin Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.) You have the following 3 operations permitted on a word: a) Insert a characterb) Delete a characterc) …