Leetcode 1: Two sums

https://leetcode.com/problems/two-sum/ Two Sum Total Accepted: 141545 Total Submissions: 770154 Difficulty: Medium Given an array of integers, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2. Please …

Leetcode 33: Search in Rotated Sorted Array

https://leetcode.com/problems/search-in-rotated-sorted-array/ Search in Rotated Sorted Array Total Accepted: 72911 Total Submissions: 252621 Difficulty: Hard Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). You are given a target value to search. If found in …

Leetcode 272: Closest Binary Search Tree Value II

https://leetcode.com/problems/closest-binary-search-tree-value-ii/ Closest Binary Search Tree Value II Total Accepted: 1212 Total Submissions: 4499 Difficulty: Hard Given a non-empty binary search tree and a target value, find k values in the BST that are closest to the target. Note: Given target value is a floating point. You may assume k is always valid, that is: k …

Leetcode 10: Regular Expression Matching

https://leetcode.com/problems/regular-expression-matching/ Regular Expression Matching Total Accepted: 57005 Total Submissions: 274700 Difficulty: Hard Implement regular expression matching with support for '.' and '*'. ‘.’ Matches any single character. ‘*’ Matches zero or more of the preceding element. The matching should cover the entire input string (not partial). The function prototype should be: bool isMatch(const char *s, …

Leetcode 270: Closest Binary Search Tree Value

https://leetcode.com/problems/closest-binary-search-tree-value/ Closest Binary Search Tree Value Total Accepted: 2218 Total Submissions: 7604 Difficulty: Easy Given a non-empty binary search tree and a target value, find the value in the BST that is closest to the target. Note: Given target value is a floating point. You are guaranteed to have only one unique value in the …

Leetcode 275 : H-Index II

https://leetcode.com/discuss/56122/standard-binary-search H-Index II Total Accepted: 7373 Total Submissions: 23549 Difficulty: Medium Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize your algorithm? Code 1:  class Solution(object): def hIndex(self, citations): “”” :type citations: List[int] :rtype: int “”” if citations is None or len(citations) == 0: return 0 for …

Leetcode 274: H-index

https://leetcode.com/problems/h-index/ H-Index Total Accepted: 10163 Total Submissions: 40365 Difficulty: Medium Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher’s h-index. According to the definition of h-index on Wikipedia: “A scientist has index h if h of his/her N papers have at least h …

Leetcode 280: Wiggle Sort

https://leetcode.com/problems/wiggle-sort/ Wiggle Sort Total Accepted: 1570 Total Submissions: 3651 Difficulty: Medium Given an unsorted array nums, reorder it in-place such that nums[0] <= nums[1] >= nums[2] <= nums[3]…. For example, given nums = [3, 5, 2, 1, 6, 4], one possible answer is [1, 6, 2, 5, 3, 4]. Code: class Solution(object): def wiggleSort(self, nums): …