Given a non-empty array of integers, return the third maximum number in this array. If it does not exist, return the maximum number. The time complexity must be in O(n). Example 1:<br />Input: [3, 2, 1] Output: 1 Explanation: The third maximum is 1.<br />Example 2:<br />Input
Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements. Example: Input: [0,1,0,3,12]<br />Output: [1,3,12,0,0]<br />Note: You must do this in-place without making a copy of the array.<br />Minimize
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array. Example 1: Input: [3,0,1]<br />Output: 2<br />Example 2: Input: [9,6,4,2,3,5,7,0,1]<br />Output: 8<br />Note:<br />Your algorithm should run in linear runtime
Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the absolute difference between i and j is at most k. Example 1: Input: nums = [1,2,3,1], k = 3<br />Output: true<br />Example 2:
Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct. Example 1: Input: [1,2,3,1]<br />Output: true<br />Example 2:
Given an array, rotate the array to the right by k steps, where k is non-negative. Follow up: Try to come up with as many solutions as you can, there are at least 3 different ways to solve this problem.<br />Could you do it in-place with O(1) extra space?<br /> Example
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. You may assume that the array is non-empty and the majority element always exist in the array. Example 1: Input: [3,2,3]<br />Output: 3
Say you have an array prices for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete as many transactions as you like (i.e., buy one and sell one share of the stock multiple times). Note: You may not engage i
Given an integer rowIndex, return the rowIndexth row of Pascal's triangle. Notice that the row index starts from 0. <br />In Pascal's triangle, each number is the sum of the two numbers directly above it. Follow up: Could you optimize your algorithm to use only O(k) ex
Given a non-negative integer numRows, generate the first numRows of Pascal's triangle. <br />In Pascal's triangle, each number is the sum of the two numbers directly above it. Example: Input: 5<br />Output:<br />[<br /> [1],<br /> [1,1],<br />&
<pre class="language-csharp"><code>public class Solution { public void Merge(int[] nums1, int m, int[] nums2, int n) { int i=m-1; int j=n-1; for(int x=m+n-1;x>=0;x--){ if(i >= 0 && j >= 0){ if(nums1[i]>nums2[j]){
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You may assume no duplicates in the array. Example 1: Input: [1,3,5,6], 5<br />Output: 2<br />Example 2: Input: [1