1.Two Sum
desc
Given an array of integers, return indices of the two numbers such that they add up to a specific target.
You may assume that each input would have exactly one solution, and you may not use the same element twice.
Example:
1 | Given nums = [2, 7, 11, 15], target = 9, |
solution
s.eg1.
1 | //24 ms 38 MB s.O(n^2) k.O(1) |
eg2.
1 | // 3 ms 37.2 MB s.O(n) k.O(n) |
2.Add Two Numbers
des
You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.
You may assume the two numbers do not contain any leading zero, except the number 0 itself.
Example:
1 | Input: (2 -> 4 -> 3) + (5 -> 6 -> 4) |
solution
eg1.
1 | // 2 ms 44.7 MB |
3.Longest Substring Without Repeating Characters
desc
Given a string, find the length of the longest substring without repeating characters.
Example 1:
1 | Input: "abcabcbb" |
Example 2:
1 | Input: "bbbbb" |
Example 3:
1 | Input: "pwwkew" |
solution
eg1.
1 | //2 ms 24.05% 36.9 MB 95.35% |
eg2.
1 | // 2 ms 37.3 MB |
4.Median of Two Sorted Arrays
desc
There are two sorted arrays nums1 and nums2 of size m and n respectively.
Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).
You may assume nums1 and nums2 cannot be both empty.
Example 1:
1 | nums1 = [1, 3] |
Example 2:
1 | nums1 = [1, 2] |
solution
eg1.
1 | // 20 ms 10.07% |
eg2.
1 | class Solution { |
eg3.
1 | // 二分查找、分治算法 |