442. Find All Duplicates in an Array

Description:

https://leetcode.com/problems/find-all-duplicates-in-an-array/description/

Code:

 

Time & Space:
O(n) & O(1)

448. Find All Numbers Disappeared in an Array

Description:

https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array/description/

Code:

 

Code for fastest algorithm:

 

Time & Space:
O(n) & O(1)

495. Teemo Attacking

Description:

https://leetcode.com/problems/teemo-attacking/description/

Code:

 

Time & Space:
O(n) & O(1)

532. K-diff Pairs in an Array

Description:

https://leetcode.com/problems/k-diff-pairs-in-an-array/description

Code:

Time & Space:
O(nlog(n)) & O(n)

485. Max Consecutive Ones

Description:

https://leetcode.com/problems/max-consecutive-ones/description/

Code:

 

Time & Space:
O(n) & O(1)

628. Maximum Product of Three Numbers


Description:

https://leetcode.com/problems/maximum-product-of-three-numbers/description/


Code:


Time & Space:

O(n) & O(1)

621. Task Scheduler

Description:
https://leetcode.com/problems/task-scheduler/description/

Code:

 

Time & Space:
Record: O(1)
Sort: O(nlogn)
Calculate idle: O(1)

Space: O(1)

611. Valid Triangle Number

Description:

https://leetcode.com/problems/valid-triangle-number/description/

Algorithm1:

Use for loop for three times.

It works but slow (beats 23.60%)

Code1:

 

Timing & Space:

O(n^3) & O(1)

 

Algorithm2:

 

Code2:

 

Timing & Space:

Time:

Worst: O(n^2)

Best: O(1)

Space: O(1)