Leetcode - Sort Array By Parity
Leetcode - Third Maximum Number

Leetcode - Height Checker

violet posted @ Jul 14, 2020 08:20:21 AM in 算法 with tags Algorithm Golang array 非人也 , 465 阅读

https://leetcode.com/problems/height-checker/

Students are asked to stand in non-decreasing order of heights for an annual photo.

Return the minimum number of students that must move in order for all students to be standing in non-decreasing order of height.

Notice that when a group of students is selected they can reorder in any possible way between themselves and the non selected students remain on their seats.

 

Example 1:

Input: heights = [1,1,4,2,1,3]
Output: 3
Explanation: 
Current array : [1,1,4,2,1,3]
Target array  : [1,1,1,2,3,4]
On index 2 (0-based) we have 4 vs 1 so we have to move this student.
On index 4 (0-based) we have 1 vs 3 so we have to move this student.
On index 5 (0-based) we have 3 vs 4 so we have to move this student.

 

func heightChecker(heights []int) int {
	originHeights := make([]int, len(heights))
	for index, item := range heights {
		originHeights[index] = item
	}
	sort.Ints(heights)
	count := 0
	for i := 0; i < len(heights); i++ {
		if originHeights[i] != heights[i] {
			count++
		}
	}

	return count
}
How to Get Pin code 说:
Nov 02, 2022 04:45:26 PM

Technology offers a new phase in various sectors. There is a positive impact on simple applications such as location search (maps), online shopping platforms, and many digital services. Today product and service delivery are fast and effective within hours or a few days. How to Get Pin code of MY Location Right Now Using GPS The internet provides online websites/platforms to help organizations market their product effectively. However, the user needs to provide location details (current location pin code) to receive the delivery.

APGLI Bond 说:
Nov 05, 2022 06:31:02 PM

Andhra Pradesh government life insurance department (APGLI) is one of the oldest and effective departments in the state. It’s a popular social security scheme implemented to help the state government employees. APGLI Bond APGLI was officially establish in 1907 by Nizam of the erstwhile state of Hyderabad for the welfare of the state employees. The scheme works under the Administrative Control of Finance Department.

MIS Portal Haryana 说:
Nov 11, 2022 06:00:56 PM

Management Information System (MIS) had been launched by Government of Haryana in education sector. It is called as MIS Haryana. Also named as Saksham Haryana Education Portal. MIS Portal Haryana This is an online portal by the department of Education. Haryana Education portal is for all education officers, teachers and students to access all technology systems. This article provides you details about MIS Haryana and procedure to get login to the website.

pf trrn status 说:
Dec 16, 2022 09:23:36 PM

TRRN Stands for Temporary Return Reference Number. The TRRN is the id number get by the EPFO for a payment transaction when a PF account holder or an employer makes an online payment toward the PF monthly contribution. pf trrn status TRRN is an abbreviation for Temporary Return Reference Number, which is used to check the status of PF Challan payments.

Plus Two Model Paper 说:
Feb 16, 2023 04:08:18 PM

Plus Two Model Paper 2024 and Board Model Paper 2024 The Board of Secondary Education has declared the Board Model Paper 2024 of 2nd Year Intermediate Class. Plus Two Model Paper 2024 If you are also one of the enrolling students of this board and waiting for 2nd Year Intermediate Model Paper 2024. Important Question Paper 2024 then take the patient for some time and check the final passing list through the link which is mentioned at the bottom of the page.

boardmodelpaper.com 说:
Jan 28, 2024 01:19:12 AM

Board Model Papers 2024 provide all states of 6th to 10th text books 2024 Candidates who are Searching for 6th to 10th and 11th to 12th text books and syllabus, sample questions, exam pattern, and Co-Curricular Subject textbooks can refer to this entire article. boardmodelpaper.com and question papers for following the website and Arts, Science, Commerce Stream Subject Wise Solved Question Bank for Hindi & English Medium Students with Exam Pattern & Blueprint and subject Wise with 11th & 12th Question Bank 2024 for General & Vocational Course. Here, we have gathered all subjects of Board textbooks for all Class along with the direct download links.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter