Leetcode 3: Longest Substring Without Repeating Characters

https://leetcode.com/problems/longest-substring-without-repeating-characters/   Longest Substring Without Repeating Characters Total Accepted: 95017 Total Submissions: 467741 Difficulty: Medium Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating characters for “abcabcbb” is “abc”, which the length is 3. For “bbbbb” the longest substring is “b”, with the length …

Leetcode 90: Find all possible subsets of a subset

https://leetcode.com/problems/subsets-ii/ Subsets II Total Accepted: 47791 Total Submissions: 170711 Difficulty: Medium Given a collection of integers that might contain duplicates, nums, return all possible subsets. Note: Elements in a subset must be in non-descending order. The solution set must not contain duplicate subsets. For example,If nums = [1,2,2], a solution is: [ [2], [1], [1,2,2], …

Leetcode 218: The Skyline Problem

https://leetcode.com/problems/the-skyline-problem/ The Skyline Problem A city’s skyline is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Now suppose you are given the locations and height of all the buildings as shown on a cityscape photo (Figure A), write a program to output the skyline …

Leetcode 42: Trapping Rain Water

Trapping Rain Water Total Accepted: 47601 Total Submissions: 157411 Difficulty: Hard Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. For example, Given [0,1,0,2,1,0,1,3,2,1,2,1], return 6. https://leetcode.com/problems/trapping-rain-water/   Naive idea: traverse from left to right. left[i] means …

Leetcode 141: Linked List Cycle

Linked List Cycle   Total Accepted: 74414 Total Submissions: 204066 Difficulty: Medium Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using extra space? https://leetcode.com/problems/linked-list-cycle/   Naive: O(N) space, O(N) time # Definition for singly-linked list. # class ListNode(object): # def __init__(self, x): # self.val …

Leetcode 282: Expression Add Operators

Expression Add Operators https://leetcode.com/problems/expression-add-operators/ Given a string that contains only digits 0-9 and a target value, return all possibilities to add operators +, -, or * between the digits so they evaluate to the target value. Examples: “123”, 6 -> [“1+2+3”, “1*2*3”] “232”, 8 -> [“2*3+2”, “2+3*2”] “00”, 0 -> [“0+0”, “0-0”, “0*0”] “3456237490”, 9191 …