Design an iterator to flatten a 2D vector. It should support the next and hasNext operations.
next
hasNext
Implement the Vector2D class:
Vector2D
Vector2D(int[][] vec)
vec
next()
Given an integer array nums, reorder it such that nums[0] < nums[1] > nums[2] < nums[3]....
nums
nums[0] < nums[1] > nums[2] < nums[3]...
You may assume the input array always has a valid answer.
Example 1:
Input: nums = [1,5,1,1,6,4]Output: [1,6,1,5,1,4]…
Given an integer array nums, design an algorithm to randomly shuffle the array. All permutations of the array should be equally likely as a result of the shuffling.
Implement the Solution class:
Solution
Solution(int[] nums)
Given two integers representing the numerator and denominator of a fraction, return the fraction in string format.
numerator
denominator
If the fractional part is repeating, enclose the repeating part in parentheses.
Given an n x n matrix where each of the rows and columns is sorted in ascending order, return the kth smallest element in the matrix.
n x n
matrix
kth
Note that it is the kth smallest element in the sorted order, not the kth distinct element.
Suppose you are at a party with n people labeled from 0 to n - 1 and among them, there may exist one celebrity. The definition of a celebrity is that all the other n - 1 people know the celebrity, but the celebrity does not know any of them.
n
0
n - 1
Given the root of a binary search tree and a node p in it, return the in-order successor of that node in the BST. If the given node has no in-order successor in the tree, return null.
root
p
null
Given four integer arrays nums1, nums2, nums3, and nums4 all of length n, return the number of tuples (i, j, k, l) such that:
nums1
nums2
nums3
nums4
(i, j, k, l)
0 <= i, j, k, l < n
nums1[i] + nums2[j] + nums3[k] + nums4[l] == 0
Assume the following rules are for the tic-tac-toe game on an n x n board between two players: