算法题,持续更新

1.Medium

Asked by Pinterest
Given an integer list where each number represents the number of hops you can make, determine whether you can reach to the last index starting at index 0.
For example, [2, 0, 1, 0] returns True while [1, 1, 0, 1] returns False.
给定一个整数列表,其中每个数字表示您可以进行的跳数,确定您是否可以到达从索引0开始的最后一个索引。 例如, [2, 0, 1, 0] 返回 真 而 [1,1,0,1] 返回 假.

2.Easy

Asked by Microsoft
Print the nodes in a binary tree level-wise. For example, the following should print 1, 2, 3, 4, 5.
在这里插入图片描述
按级别打印二叉树中的节点。例如,下面应该输出1、2、3、4、5.

3.Easy

Asked by Google
Given two strings A and B, return whether or not A can be shifted some number of times to get B.
For example, if A is abcde and B is cdeab, return true. If A is abc and B is acb, return false.
给定两个字符串A和B,返回A是否可以被移位一些次数以得到B。 例如,A 是 abcde 和 B 是 cdeab ,返回true。如果 A 是 abc 和 B是 acb, 返回false。

4.Medium

Asked by Cisco
Given an unsigned 8-bit integer, swap its even and odd bits. The 1st and 2nd bit should be swapped, the 3rd and 4th bit should be swapped, and so on.
For example, 10101010 should be 01010101. 11100010 should be 11010001.
Bonus: Can you do this in one line?
给定一个无符号8位整数,交换其奇数位和偶数位。第1位和第2位应该交换,第3位和第4位应该交换,以此类推。 例如, 10101010 应该是 01010101. 11100010 应该是 11010001. 附加提示:你能在一行中完成吗?

5.Medium

Asked by Facebook
Given a binary tree, return all paths from the root to leaves.
For example, given the tree:
Return [[1, 2], [1, 3, 4], [1, 3, 5]].
在这里插入图片描述
给定一棵二叉树,返回从根到叶的所有路径。 例如,给定树:如上图,返回 [1,2], [1,3,4], [1,3,5]]

6.Hard

Asked by Google
Given a word W and a string S, find all starting indices in S which are anagrams of W.
For example, given that W is “ab”, and S is “abxaba”, return 0, 3, and 4.
给定一个单词 W 和一个字符串 S,找到所有的起始索引 S 包含单词 W . 例如,假设W是“ab”,S是“abxaba”,则返回0、3和4。

7.Hard

Asked by Twitter
Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.
Assume that each node in the tree also has a pointer to its parent.
According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes v and w as the lowest node in T that has both v and w as descendants
(where we allow a node to be a descendant of itself).”
给定一棵二叉树,找出树中两个给定节点的最低共同祖先(LCA)。假设树中的每个节点都有一个指向其父节点的指针。 根据维基百科对LCA的定义:“在两个节点v和w之间,最低共同祖先被定义为T中同时具有v和w后代的最低节点(在这里,我们允许一个节点是它自己的后代)。”

8.Medium

Asked by Google
Given a string of words delimited by spaces, reverse the words in string. For example, given “hello world here”, return “here world hello”
Follow-up: given a mutable string representation, can you perform this operation in-place?
给定一个由空格分隔的单词字符串,反转字符串中的单词。例如,给定"hello world here",返回"here world hello" 后续:给定一个可变的字符串表示,你能就地执行这个操作吗?

9.Hard

Asked by Facebook
Given a string and a set of delimiters, reverse the words in the string while maintaining the relative order of the delimiters. For example, given “hello/world:here”, return “here/world:hello”
Follow-up: Does your solution work for the following cases: “hello/world:here/”, “hello//world:here”
给定一个字符串和一组分隔符,反转字符串中的单词,同时保持分隔符的相对顺序。例如,给定“hello/world:here”,返回“here/world:hello”。 后续:您的解决方案是否适用于以下情况:“hello/world:here/”,“hello//world:here”

10.Hard

Asked by Google
Given two non-empty binary trees s and t, check whether tree t has exactly the same structure and node values with a subtree of s. A subtree of s is a tree consists of a node in s and all of this node’s descendants. The tree s could also be considered as a subtree of itself.
给定两个非空二叉树 年代 和 t,检查树是否 t 的子树有完全相同的结构和节点值 年代. 的子树 年代 树是由节点组成的吗 年代 以及所有这些节点的后代。这棵树 年代 也可以看作是它自身的一个子树

11.Medium

Asked by Jane Street
Generate a finite, but an arbitrarily large binary tree quickly in O(1).
That is, generate() should return a tree whose size is unbounded but finite.
在O(1)中快速生成一个有限的,但任意大的二叉树。 也就是说, generate() 应该返回一个大小无界但有限的树

12.Easy

Asked by Facebook
Given a binary tree, return the level of the tree with minimum sum.
给定一棵二叉树,返回树的和最小的级别

13.Easy

Given a sorted list of integers, square the elements and give the output in sorted order.
For example, given [-9, -2, 0, 2, 3], return [0, 4, 4, 9, 81].
给定一个已排序的整数列表,对元素进行平方,并按排序顺序给出输出。例如,给定[-9,-2,0,2,3],返回[0,4,4,9,81]。

14.Medium

Asked by Google
Given a set of closed intervals, find the smallest set of numbers that covers all the intervals. If there are multiple smallest sets, return any of them.
For example, given the intervals [0, 3], [2, 6], [3, 4], [6, 9], one set of numbers that covers all these intervals is {3, 6}.
给定一组闭区间,找出覆盖所有区间的最小数集。如果有多个最小的集合,则返回其中任何一个。 例如,给定区间 [0,3], [2,6], [3,4], [6,9],一组覆盖所有这些区间的数字是 {3、6}.

15.Medium

Asked by Microsoft
Implement the singleton pattern with a twist. First, instead of storing one instance, store two instances. And in every even call of getInstance(), return the first instance and in every odd call of getInstance(), return the second instance.
实现一个扭转的单例模式。首先,存储两个实例,而不是一个实例。在每一次的召唤中 getInstance (),返回第一个实例,并在每个奇数调用 getInstance (),返回第二个实例。

16.Hard

Asked by Google
Given a string which we can delete at most k, return whether you can make a palindrome.
For example, given ‘waterrfetawx’ and a k of 2, you could delete f and x to get ‘waterretaw’.
给定一个最多可以删除k个字符的字符串,返回是否可以生成回文。 例如,给定'waterrfetawx'和一个k为2,你可以删除f和x得到'waterretaw'。

17.Medium

Asked by Zillow
You are given a 2-d matrix where each cell represents number of coins in that cell. Assuming we start at matrix[0][0], and can only move right or down, find the maximum number of coins you can collect by the bottom right corner.
For example, in this matrix
0 3 1 1 2 0 0 4 1 5 3 1
The most we can collect is 0 + 2 + 1 + 5 + 3 + 1 = 12 coins.
在这里插入图片描述
你得到一个二维的 矩阵 每个单元格表示该单元格中的硬币数量。假设我们从 矩阵[0][0],并且只能向右或向下移动,在右下角找到你可以收集的最大数量的硬币。 例如,在这个矩阵中,我们最多可以收集到0 + 2 + 1 + 5 + 3 + 1 = 12个硬币。”

18.Hard

Asked by LinkedIn
Given a string, return whether it represents a number. Here are the different kinds of numbers:
“10”, a positive integer
“-10”, a negative integer
“10.1”, a positive real number
“-10.1”, a negative real number
“1e5”, a number in scientific notation
And here are examples of non-numbers:
“a”
“x 1”
“a -2”
“-”
给定一个字符串,返回它是否代表一个数字。以下是不同类型的数字:
“10”,一个正整数
“-10”,一个负整数
“10.1”,一个正实数
“-10.1”,一个负数
“1e5”,科学记数法中的数字
这里有一些非数字的例子:
"a"
"x 1"
"a -2"
"-"

19.Easy

Asked by Microsoft
You have n fair coins and you flip them all at the same time. Any that come up tails you set aside. The ones that come up heads you flip again. How many rounds do you expect to play before only one coin remains?
Write a function that, given n, returns the number of rounds you’d expect to play until one coin remains.
你有 n 均匀硬币,同时抛。任何出现反面的你都把它放在一边。正面朝上的再抛一次。在只剩下一枚硬币之前,你预计要玩多少回合? 写出一个给定的函数 n,返回在剩下一枚硬币之前你希望玩的轮数。

20.Easy

Asked by Google
Given the root of a binary search tree, and a target K, return two nodes in the tree whose sum equals K.
For example, given the following tree and K of 20
Return the nodes 5 and 15.
树
给定二叉搜索树的根,和一个目标 K,返回树中两个和等于的节点 K. 例如,给定上面的树和 K 20,如图,返回的节点 5 和 15.


总结

提示:持续更新中,(*╹▽╹*)~~~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

海啦啦喽

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值