Memory Allocation

  • Home

  • Tags

  • Categories

  • Archives

  • Commonweal 404

  • Search

Contains Duplicates

Posted on 2018-05-27 | Edited on 2018-12-19 | In interview questions |

219. Contains Duplicates II

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.

给一个数组, 看nums[i]附近的k个数里, 是否有相同的. 也就是说, 如果存在nums[i] == nums[j]和abs(j-i) <= k则返回True 否则返回 False.

Read more »

Maximum Distance in Arrays

Posted on 2018-05-27 | Edited on 2018-12-19 | In interview questions |

624. Maximum Distance in Arrays

Given m arrays, and each array is sorted in ascending order. Now you can pick up two integers from two different arrays (each array picks one) and calculate the distance. We define the distance between two integers a and b to be their absolute difference |a-b|. Your task is to find the maximum distance.

给一个嵌套的数组, 里面至少有两个数组, 每个数组里面至少有一个数字. 每个数组都是排序好的. 求最大的数字里头最大的差值. 需要注意的是如果从一个数组里选了最大值, 那个最小值就不能从这个数组里面选择了.

Read more »

Remove Duplicates from Sorted Array

Posted on 2018-05-27 | Edited on 2018-12-19 | In interview questions |

26. Remove Duplicates from Sorted Array

Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length.
Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.

输入是一个排序好的数组, 我们需要去掉所有重复的元素, 然后返回这个数组的长度. 值得注意的是, 题目还要求: 1. 不能使用额外的空间. 2. 需要in-place修改

Read more »

Maximum Average Subarray I

Posted on 2018-05-27 | Edited on 2018-12-19 | In interview questions |

643. Maximum Average Subarray I

Given an array consisting of n integers, find the contiguous subarray of given length k that has the maximum average value. And you need to output the maximum average value.

意思是, 给一个长度为n的数组, 和一个值k, 求所有长度为k的字数组的最大平均值.

Read more »

TaskScheduler

Posted on 2018-05-21 | Edited on 2018-12-19 | In interview questions |

621. Task Scheduler

Given a char array representing tasks CPU need to do. It contains capital letters A to Z where different letters represent different tasks.Tasks could be done without original order. Each task could be done in one interval. For each interval, CPU could finish one task or just be idle.
However, there is a non-negative cooling interval n that means between two same tasks, there must be at least n intervals that CPU are doing different tasks or just be idle.
You need to return the least number of intervals the CPU will take to finish all the given tasks.

输入是一组任务, 和一个冷却的时间$n$. 两个相同任务之间的至少要冷却$n$. 要求返回执行完所有任务所需要最少的时间.

Read more »

Sum of Left Leaves

Posted on 2018-05-21 | Edited on 2018-12-19 | In interview questions |

Sum of Left Leaves

Find the sum of all left leaves in a given binary tree

输入一棵二叉树, 返回所有左叶子的和.

Example:

   3
 /   \
9     20
     /   \
   15     7

其中, 左叶子为 9, 15, 所以返回 24

Read more »

Flatten Nested List Iterator

Posted on 2018-05-21 | Edited on 2018-12-19 | In interview questions |

341. Flatten Nested List

Given a nested List of Integers, implement an iterator to flatten it.

给一个嵌套数组, 要求做一个迭代器去把这个嵌套的数组压平

Example 1:
[[1, 1], 2, [1, 1]] 压平后 [1, 1, 2, 1, 1]

Example 2:
[1, [4, [6]]] 压平后 [1, 4, 6]

Read more »

Number of Longest Increase Subsequence

Posted on 2018-05-20 | Edited on 2018-12-19 | In interview questions |

678. Number of Longest Increasing Subsequence

Given a unsorted array of intergers, find the number of longest increasing subsequence.

给一个数组返回最长递增字串的个数

例子1:

[1, 3, 5, 4, 7] -> 2

最长的两个递增字串是 [1, 3, 4, 7], [1, 3, 5, 7]

例子2:

[2, 2, 2, 2, 2] -> 5

最长递增字串是1, 这样的字串有5个

Read more »
1…345
Jiakuan Li

Jiakuan Li

雷霆雨露,俱是天恩

39 posts
6 categories
28 tags
GitHub Twitter
© 2019 Jiakuan Li