Leetcode 99: Validate Binary Search Tree

https://leetcode.com/problems/validate-binary-search-tree/ Validate Binary Search Tree Total Accepted: 65929 Total Submissions: 326515 Difficulty: Medium Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node’s key. The right subtree of a …

leetcode 61: Rotate List

https://leetcode.com/problems/rotate-list/ Rotate List Total Accepted: 50875 Total Submissions: 233034 Difficulty: Medium Given a list, rotate the list to the right by k places, where k is non-negative. For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL.   Code # Definition for singly-linked list. # class ListNode(object): # def __init__(self, x): # self.val = x # self.next …

Leetcode 26: Remove Duplicates from Sorted Array

https://leetcode.com/problems/remove-duplicates-from-sorted-array/ Remove Duplicates from Sorted Array Total Accepted: 87967 Total Submissions: 280545 Difficulty: Easy Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. Do not allocate extra space for another array, you must do this in place with constant memory. For example,Given input …

Leetcode 53: Maximum Subarray

https://leetcode.com/problems/maximum-subarray/ Maximum Subarray Total Accepted: 79595 Total Submissions: 227725 Difficulty: Medium Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For example, given the array [−2,1,−3,4,−1,2,1,−5,4],the contiguous subarray [4,−1,2,1] has the largest sum = 6. click to show more practice. More practice: If you have figured out …

Leetcode 60: Permutation Sequence

https://leetcode.com/problems/permutation-sequence/ Permutation Sequence Total Accepted: 40547 Total Submissions: 173795 Difficulty: Medium The set [1,2,3,…,<i>n</i>] contains a total of n! unique permutations. By listing and labeling all of the permutations in order,We get the following sequence (ie, for n = 3): "123" "132" "213" "231" "312" "321" Given n and k, return the kth permutation sequence. …

Leetcode 46: Permutations

https://leetcode.com/problems/permutations/ Permutations Total Accepted: 70053 Total Submissions: 214523 Difficulty: Medium Given a collection of numbers, return all possible permutations. For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1].   Code class Solution(object): def permute(self, nums): “”” :type nums: List[int] :rtype: List[List[int]] “”” if not nums: return [] res = [] self.recur(nums, 0, …

Leetcode 99: Recover Binary Search Tree

https://leetcode.com/problems/recover-binary-search-tree/ Recover Binary Search Tree Total Accepted: 41308 Total Submissions: 166942 Difficulty: Hard Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing its structure. Note:A solution using O(n) space is pretty straight forward. Could you devise a constant space solution? confused what "{1,#,2,3}" means? > read more …

Leetcode 239: Sliding Window Maximum

https://leetcode.com/problems/sliding-window-maximum/ Sliding Window Maximum Total Accepted: 13329 Total Submissions: 57131 Difficulty: Hard Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window moves right …

Find Kth Smallest Element in Two Sorted Arrays

Problem Given K and two sorted arrays with length M and N, find the K-th smallest element among all elements in the two arrays.   Code import sys class Solution(object): def findKthSmallest(self, nums1, nums2, k): “”” :type nums1: sorted List[int] :type nusm2: sorted List[int] :type k: int :rtype: int “”” if not (0 <k <= …

Leetcode 43: Multiply Strings

https://leetcode.com/problems/multiply-strings/ Multiply Strings Total Accepted: 43669 Total Submissions: 203735 Difficulty: Medium Given two numbers represented as strings, return multiplication of the numbers as a string. Note: The numbers can be arbitrarily large and are non-negative. It is not a very funny problem that can test you in the interview.   Refer Idea here: https://leetcode.com/discuss/33951/ac-solution-in-java-with-explanation Refer …