leetcode 350. Intersection of Two Arrays II

难度:Easy

leetcode
九章

题目描述

Given two arrays, write a function to compute their intersection.

Example 1:

Input: nums1 = [1,2,2,1], nums2 = [2,2]
Output: [2,2]

Example 2:

Input: nums1 = [4,9,5], nums2 = [9,4,9,8,4]
Output: [4,9]

Note:

  • Each element in the result should appear as many times as it shows in both arrays.
  • The result can be in any order.

Follow up:

  • What if the given array is already sorted? How would you optimize your algorithm?
  • What if nums1 ‘s size is small compared to nums2 ‘s size? Which algorithm is better?
  • What if elements of nums2 are stored on disk, and the memory is limited such that you cannot load all elements into the memory at once?

Tags: Hash Table, Two Pointers, Binary Search, Sort

Difficulty: Easy

答案

leetcode 118. Pascal's Triangle

难度:Easy

leetcode
九章

题目描述

Given two arrays, write a function to compute their intersection.

Example 1:

Input: nums1 = [1,2,2,1], nums2 = [2,2]
Output: [2,2]

Example 2:

Input: nums1 = [4,9,5], nums2 = [9,4,9,8,4]
Output: [4,9]

Note:

  • Each element in the result should appear as many times as it shows in both arrays.
  • The result can be in any order.

Follow up:

  • What if the given array is already sorted? How would you optimize your algorithm?
  • What if nums1 ‘s size is small compared to nums2 ‘s size? Which algorithm is better?
  • What if elements of nums2 are stored on disk, and the memory is limited such that you cannot load all elements into the memory at once?

Tags: Hash Table, Two Pointers, Binary Search, Sort

Difficulty: Easy

答案

leetcode 242. Valid Anagram

难度:Easy

leetcode
九章

题目描述

Given two strings s and t _, write a function to determine if _t is an
anagram of s.

Example 1:

Input: _s_ = "anagram", _t_ = "nagaram"
Output: true

Example 2:

Input: _s_ = "rat", _t_ = "car"
Output: false

Note:
You may assume the string contains only lowercase alphabets.

Follow up:
What if the inputs contain unicode characters? How would you adapt your
solution to such case?

Tags: Hash Table, Sort

Difficulty: Easy

答案

leetcode 179. Largest Number

难度:Middle

leetcode
九章

题目描述

Given a list of non negative integers, arrange them such that they form the
largest number.

Example 1:

Input: [10,2]
Output: "210"

Example 2:

Input: [3,30,34,5,9]
Output: "9534330"

Note: The result may be very large, so you need to return a string instead
of an integer.

Tags: Sort

Difficulty: Medium

答案


:D 一言句子获取中...