163. Missing Ranges Total Accepted: 19465 Total Submissions: 66232 Difficulty: Medium Contributors: Admin Given a sorted integer array where the range of elements are in the inclusive range [lower, upper], return its missing ranges. For example, given [0, 1, 3, 50, 75], lower = 0 and upper = 99, return ["2", "4->49", "51->74", "76->99"]. …
Category Archives: leetcode
Leetcode 388: Longest Absolute File Path
388. Longest Absolute File Path Total Accepted: 11837 Total Submissions: 35565 Difficulty: Medium Contributors: Admin Suppose we abstract our file system by a string in the following manner: The string "dir\n\tsubdir1\n\tsubdir2\n\t\tfile.ext" represents: dir subdir1 subdir2 file.ext The directory dir contains an empty sub-directory subdir1 and a sub-directory subdir2 containing a file file.ext. The string "dir\n\tsubdir1\n\t\tfile1.ext\n\t\tsubsubdir1\n\tsubdir2\n\t\tsubsubdir2\n\t\t\tfile2.ext" …
Leetcode 198: House Robber
https://leetcode.com/problems/house-robber/ 198. House Robber Total Accepted: 101581 Total Submissions: 275668 Difficulty: Easy Contributors: Admin You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security system connected and it …
Leetcode 298: Binary Tree Longest Consecutive Sequence
https://leetcode.com/problems/binary-tree-longest-consecutive-sequence/ Given a binary tree, find the length of the longest consecutive sequence path. The path refers to any sequence of nodes from some starting node to any node in the tree along the parent-child connections. The longest consecutive path need to be from parent to child (cannot be the reverse). For example, 1 \ …
Continue reading “Leetcode 298: Binary Tree Longest Consecutive Sequence”
Leetcode 70: Climbing Stairs
70. Climbing Stairs Total Accepted: 139063 Total Submissions: 363734 Difficulty: Easy Contributors: Admin You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? Code from math import sqrt …
Leetcode 258: Add Digits
258. Add Digits Total Accepted: 134747 Total Submissions: 269960 Difficulty: Easy Contributors: Admin Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. For example: Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one …
Leetcode 40: Combination Sum II
40. Combination Sum II Total Accepted: 89506 Total Submissions: 294097 Difficulty: Medium Contributors: Admin Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. Each number in C may only be used once in the combination. Note: All numbers (including …
Leetcode 341: Flatten Nested List Iterator
341. Flatten Nested List Iterator Total Accepted: 20339 Total Submissions: 55207 Difficulty: Medium Contributors: Admin Given a nested list of integers, implement an iterator to flatten it. Each element is either an integer, or a list — whose elements may also be integers or other lists. Example 1:Given the list [[1,1],2,[1,1]], By calling next repeatedly …
Continue reading “Leetcode 341: Flatten Nested List Iterator”
Leetcode 27: Remove Element
27. Remove Element Total Accepted: 154492 Total Submissions: 426032 Difficulty: Easy Contributors: Admin Given an array and a value, remove all instances of that value in place and return the new length. Do not allocate extra space for another array, you must do this in place with constant memory. The order of elements can be …
Leetcode 29: Divide Two Integers
29. Divide Two Integers Total Accepted: 82624 Total Submissions: 519755 Difficulty: Medium Contributors: Admin Divide two integers without using multiplication, division and mod operator. If it is overflow, return MAX_INT. Code (Naive) import sys class Solution(object): def divide(self, dividend, divisor): “”” :type dividend: int :type divisor: int :rtype: int “”” if not divisor: …