西维蜀黍的OJ Blog

🐒 Software engineer | 📷 Photographer | 👹 Urban explorer

[刷题] Sort Array - Lintcode - 839 Merge Two Sorted Interval Lists

Description

Merge two sorted (ascending) lists of interval and return it as a new sorted list. The new sorted list should be made by splicing together the intervals of the two lists and sorted in ascending order.

The intervals in the given list do not overlap.The intervals in different lists may overlap.

Example

Example1

Input: list1 = [(1,2),(3,4)] and list2 = [(2,3),(5,6)]
Output: [(1,4),(5,6)]
Explanation:
(1,2),(2,3),(3,4) --> (1,4)
(5,6) --> (5,6)

Example2

Input: list1 = [(1,2),(3,4)] and list2 = [(4,5),(6,7)]
Output: [(1,2),(3,5),(6,7)]
Explanation:
(1,2) --> (1,2)
(3,4),(4,5) --> (3,5)
(6,7) --> (6,7)
  ...


[刷题] Sort Array - Lintcode - 6 Merge Two Sorted Arrays

Description

Merge two given sorted ascending integer array A and B into a new sorted integer array.

Example

Example 1:

Input:  A=[1], B=[1]
Output: [1,1]	
Explanation:  return array merged.

Example 2:

Input:  A=[1,2,3,4], B=[2,4,5,6]
Output: [1,2,2,3,4,4,5,6]	
Explanation: return array merged.

Challenge

How can you optimize your algorithm if one array is very large and the other is very small?

  ...


[刷题] Sort Array - Lintcode - 64 Merge Sorted Array

Description

Given two sorted integer arrays A and B, merge B into A as one sorted array.

You may assume that A has enough space (size that is greater or equal to m + n) to hold additional elements from B. The number of elements initialized in A and B are m and n respectively.

Example

Example 1:

Input:[1, 2, 3] 3  [4,5]  2
Output:[1,2,3,4,5]
Explanation:
After merge, A will be filled as [1, 2, 3, 4, 5]

Example 2:

Input:[1,2,5] 3 [3,4] 2
Output:[1,2,3,4,5]
Explanation:
After merge, A will be filled as [1, 2, 3, 4, 5]
  ...


[刷题] Sort Array - Lintcode - 464 Sort Integers II

Description

Given an integer array, sort it in ascending order in place. Use quick sort, merge sort, heap sort or any O(nlogn) algorithm.

Example

Example1:

Input: [3, 2, 1, 4, 5], 
Output: [1, 2, 3, 4, 5].

Example2:

Input: [2, 3, 1], 
Output: [1, 2, 3].
  ...


[刷题] Sort Array - Lintcode - 463 Sort Integers

Description

Given an integer array, sort it in ascending order. Use selection sort, bubble sort, insertion sort or any O(n2) algorithm.

Example

Example 1:
	Input:  [3, 2, 1, 4, 5]
	Output: [1, 2, 3, 4, 5]
	
	Explanation: 
	return the sorted array.

Example 2:
	Input:  [1, 1, 2, 1, 1]
	Output: [1, 1, 1, 1, 2]
	
	Explanation: 
	return the sorted array.
  ...