Memory Allocation

  • Home

  • Tags

  • Categories

  • Archives

  • Commonweal 404

  • Search

Insert Interval

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

Insert Interval

Given a set of non-overlapping intervlas, insert a new interval into intervals(merge if necessary)

给一个组特殊的数据结构interval和一个目标interval, 每个interval有start和end. 输入的一组interval没有重合, 要求把新的interval插入到原来的那一组interval当中, 如果有需要合并的话, 对interval进行合并

Read more »

Text Justification

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

68. Text Justification

Given an array of words and a width maxWidth, format the text such that each line as exactly maxWidth characters and is fully (left and right) justified.

题目的意思是, 给一个数组, 数组里面有$n$个单词, 把这些单词按照maxWidth行存放. 每一行的两端要对齐.
需要注意的是

  1. 单词的顺序不能改变
  2. 如果一行之后一个单词, 那么这个单词要左对齐
  3. 如果空格不能均匀分布在所有间隔当中, 则左边的空格需要比右边的空格多
  4. 每行要尽可能多的放单词
    Read more »

Increasing Triplet Subsequence

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

334. Increasing Triplet Subsequence

Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the array.

题目的意思是, 给一个未排序的数组, 看是否存在 $arr[i] < arr[j] < arr[k]$. 在这里需要注意的是, $i < j < k$ 但是$i, j, k$ 不需要是连续的.

Read more »

Two Sum IV - Input is a BST

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

653. Two Sum IV - Input is a BST

Given a Binary Search Tree and a target number, return true if there exist two elements in the BST such that their sum is equal to the given target.

这是经典题Two Sum的变形, 于经典题不同的是, 这个输入从数组, 换成了二叉搜索树. 但是, 我们还是可以按照经典题的做法取解这道题.

Read more »

Word Search

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

79. Word Search

Given a 2D board and a word, find if the word exists in the grid.
The word can be constructed from letters of sequentially adjacent cell, where “adjacent” cells are those horizontally or vertically neighboring. The same letter cell may not used more than once.

题目的意思是, 给一个2d的数组, 和一个字符串, 要求返回数组里面是否可以由相邻的字母组成这个字符串.
例子如下:

[
    [A, B, C, E]
    [S, F, C, S]
    [A, D, E, E]
]

word = ABCCED -> true

ABCCED 可以由 (0, 0) -> (0, 1) -> (0, 2) -> (1, 2) -> (2, 2) -> (2, 1) 组成.

Read more »

Product of Array Except Self

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

238. Product of Array Except

Given an array nums of $n$ integers where $n>1$, return an array output such that output[i] is equal to the product of all the elemetns of nums except nums[i]

题目说的是, 给一个array, 要求返回另外一个数组. 要求是, 返回的数组里面的是原数组其他数的乘积.
比如说:
[1, 2, 3, 4]是输入, 那么输出是 [24, 12, 8, 6]. 因为 $24 = 2 \times 3 \times 4$, $12 = 1 \times 3 \times 4$.

Read more »

Add Binary

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

67. Add Binary

这道题是一道简单题, 真的很简单.
首先来看题目

Given two binary strings, return their sum (also a binary string).
The input strings are both non-empty and contains only characters 1 or 0.

意思就是, 给两个二进制的数, 返回他们相加的和.

例子:

Input a = "11", b = "1"
Output: "100"
Read more »
1…45
Jiakuan Li

Jiakuan Li

雷霆雨露,俱是天恩

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