摘要:Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level). For example:Given binary tree [3
阅读全文
摘要:On an infinite plane, a robot initially stands at (0, 0) and faces north. The robot can receive one of three instructions: "G": go straight 1 unit; "L
阅读全文
摘要:Given a binary tree, return the preorder traversal of its nodes' values. Example: My idea:ricursion OTHERS:iretator
阅读全文
摘要:Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements. Example: Note: M
阅读全文
摘要: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 spa
阅读全文
摘要:Given an input string, reverse the string word by word. My idea:删除左右两边空格,转换成数组,再把中间空格给改了,再专成字符串,用快慢指针找到单词放进去,很麻烦,所以效果不好。 执行用时 : 92 ms, 在Reverse Words
阅读全文
摘要:Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal's triangle. Note that the row index starts from 0. Follow up: Could
阅读全文
摘要:Given an array, rotate the array to the right by k steps, where k is non-negative. Example 1: Note: Try to come up as many solutions as you can, there
阅读全文
摘要:Given an array of n positive integers and a positive integer s, find the minimal length of a contiguous subarray of which the sum ≥ s. If there isn't
阅读全文
摘要:Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: My idea:for循环遍历,最后退出循环的时候也要判断,因为为1的时候我不能去给max赋值 那用双指针怎么做呢,参考
阅读全文
摘要:Given an array nums and a value val, remove all instances of that value in-place and return the new length. Do not allocate extra space for another ar
阅读全文
摘要:Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number. The function
阅读全文
摘要:Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), ..., (an, bn) which makes sum of
阅读全文
摘要:Question: Write a function that reverses a string. The input string is given as an array of characters char[]. Do not allocate extra space for another
阅读全文
摘要:题目: 编写一个函数来查找字符串数组中的最长公共前缀。 如果不存在公共前缀,返回空字符串 ""。 示例 1: 说明: 所有输入只包含小写字母 a-z 。 思路:既然给我的是字符串数组,那我要比较的就不是两个元素了,所以考虑把这些元素的元素都一个一个取出来,放进空字符串里面,然后用字符串的count方
阅读全文
摘要:题目:给定一个 haystack 字符串和一个 needle 字符串,在 haystack 字符串中找出 needle 字符串出现的第一个位置 (从0开始)。如果不存在,则返回 -1。 示例: 说明: 当 needle 是空字符串时,我们应当返回什么值呢?这是一个在面试中很好的问题。 对于本题而言,
阅读全文
摘要:题目: 给定两个二进制字符串,返回他们的和(用二进制表示)。 输入为非空字符串且只包含数字 1 和 0。 示例 1: 思路:我反正佛了我自己的思路。。先把字符串转列表,然后加0对其,因为我不会从高位加所以就颠倒相加得结果,结果是列表,再颠倒转字符串就行了。。。。我去。。这个不熟python可真难受
阅读全文
摘要:虽然仅仅只是完成了第一小题,但是这毕竟是第一次嘛 第二题是跟树有关的,没看明白,先留坑 给出二叉搜索树的根节点,该二叉树的节点值各不相同,修改二叉树,使每个节点 node 的新值等于原树中大于或等于 node.val 的值之和。 提醒一下,二叉搜索树满足下列约束条件: 节点的左子树仅包含键小于节点键
阅读全文
摘要:给定一个非负整数 numRows,生成杨辉三角的前 numRows 行。 思路:先分情况。然后迭代。。以后一定用一下递归 示例: 执行用时 : 92 ms, 在Pascal's Triangle的Python3提交中击败了6.40% 的用户 内存消耗 : 13 MB, 在Pascal's Trian
阅读全文
摘要:题目:给定一个包含 m x n 个元素的矩阵(m 行, n 列),请按照顺时针螺旋顺序,返回矩阵中的所有元素。 实例: 思路:想用一个对应矩阵全至0,然后右下左上这样寻路,走过至为1,结果遇到了越界的情况,尴尬的是我还不会处理这种情况,先留个坑。。 参考一下别人的思路,还是厉害。。。 这里说一下我早
阅读全文