Leetcode 378: Kth Smallest Element in a Sorted Matrix

Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix. Note that it is the kth smallest element in the sorted order, not the kth distinct element. Example: matrix = [ [ 1, 5, 9], [10, 11, 13], [12, …

Leetcode 9: Palindrome Number

https://leetcode.com/problems/palindrome-number/ 9. Palindrome Number   Total Accepted: 156158 Total Submissions: 467127 Difficulty: Easy Contributors: Admin Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. Some hints: Could negative integers be palindromes? (ie, -1) If you are thinking of converting the integer to string, note the restriction of using …

199: Binary Tree Right Side View

199. Binary Tree Right Side View Total Accepted: 56659 Total Submissions: 151351 Difficulty: Medium Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom. For example:Given the following binary tree, 1 <— / \ 2 3 <— \ …

Leetcode 310: Minimum Height Trees

310. Minimum Height Trees   Total Accepted: 20625 Total Submissions: 74043 Difficulty: Medium For a undirected graph with tree characteristics, we can choose any node as the root. The result graph is then a rooted tree. Among all possible rooted trees, those with minimum height are called minimum height trees (MHTs). Given such a graph, …

Leetcode 78: Subsets

78. Subsets   Total Accepted: 118197 Total Submissions: 341929 Difficulty: Medium Given a set of distinct integers, nums, return all possible subsets. Note: The solution set must not contain duplicate subsets. For example,If nums = [1,2,3], a solution is: [ [3], [1], [2], [1,2,3], [1,3], [2,3], [1,2], [] ] Subscribe to see which companies asked …

Leetcode 94: Binary Tree Inorder Traversal

94. Binary Tree Inorder Traversal Total Accepted: 151532 Total Submissions: 358835 Difficulty: Medium Given a binary tree, return the inorder traversal of its nodes’ values. For example:Given binary tree [1,null,2,3], 1 \ 2 / 3 return [1,3,2]. Note: Recursive solution is trivial, could you do it iteratively?   Code (recursive) # Definition for a binary …

Leetcode 151: Reverse Words in a String

151. Reverse Words in a String  Total Accepted: 121339 Total Submissions: 769606 Difficulty: Medium Given an input string, reverse the string word by word. For example,Given s = “the sky is blue“,return “blue is sky the“. Update (2015-02-12):For C programmers: Try to solve it in-place in O(1) space. click to show clarification. Clarification: What constitutes …