191. Number of 1 Bits Total Accepted: 119474 Total Submissions: 312895 Difficulty: Easy Contributors: Admin Write a function that takes an unsigned integer and returns the number of ’1′ bits it has (also known as the Hamming weight). For example, the 32-bit integer ’11′ has binary representation 00000000000000000000000000001011, so the function should return 3. …
Author Archives: czxttkl
Leetcode 285: Inorder Successor in BST
285. Inorder Successor in BST Total Accepted: 17302 Total Submissions: 47674 Difficulty: Medium Contributors: Admin Given a binary search tree and a node in it, find the in-order successor of that node in the BST. Note: If the given node has no in-order successor in the tree, return null. Code # Definition for a …
Leetcode 253: Meeting Rooms II
253. Meeting Rooms II Total Accepted: 20906 Total Submissions: 55624 Difficulty: Medium Contributors: Admin Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],…] (si < ei), find the minimum number of conference rooms required. For example,Given [[0, 30],[5, 10],[15, 20]],return 2. Code # Definition for an interval. # class …
Leetcode 157: Read N Characters Given Read4
157. Read N Characters Given Read4 Total Accepted: 19570 Total Submissions: 66588 Difficulty: Easy Contributors: Admin The API: int read4(char *buf) reads 4 characters at a time from a file. The return value is the actual number of characters read. For example, it returns 3 if there is only 3 characters left in the file. …
Continue reading “Leetcode 157: Read N Characters Given Read4”
Leetcode 301: Remove Invalid Parentheses
301. Remove Invalid Parentheses Total Accepted: 23550 Total Submissions: 69307 Difficulty: Hard Contributors: Admin Remove the minimum number of invalid parentheses in order to make the input string valid. Return all possible results. Note: The input string may contain letters other than the parentheses ( and ). Examples: “()())()” -> [“()()()”, “(())()”] “(a)())()” -> [“(a)()()”, …
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. …
Continue reading “Leetcode 314: Binary Tree Vertical Order Traversal”
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]] …
Continue reading “Leetcode 311: Sparse Matrix Multiplication”
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 …
Continue reading “Leetcode 237: Delete Node in a Linked List”