随笔分类 - LeetCode
LeetCode题解
摘要:有效的数独 判断一个 9x9 的数独是否有效。只需要根据以下规则,验证已经填入的数字是否有效即可。 上图是一个部分填充的有效的数独。 数独部分空格内已填入了数字,空白格用 '.' 表示。 示例 1: 示例 2: 说明: 一个有效的数独(部分已被填充)不一定是可解的。 只需要根据以上规则,验证已经填入
阅读全文
摘要:https://leetcode-cn.com/explore/interview/card/top-interview-questions-easy/1/array/28/ 给定一个数组 nums,编写一个函数将所有 0 移动到数组的末尾,同时保持非零元素的相对顺序。 示例: 说明: 此题有两个思
阅读全文
摘要:题意是把一个二叉树转换成一个链表,链表的元素顺序是二叉树的先序遍历结果。 最简单的做法就是先序遍历该二叉树,将所有经过的节点的指针都依次记录在一个vector里,完成后,在将vector里的节点指针的左孩子置为NULL,右孩子置为vector中的下一个指针。具体的代码和运行效果如下 这里用了多余的空
阅读全文
摘要:Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maxim
阅读全文
摘要:Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. The same repeat
阅读全文
摘要:Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not possib
阅读全文
摘要:Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. If the number of nodes is not a multiple of k then l
阅读全文
摘要:Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. 两个字符串A和B, 在A中查找是否出现过B, 如
阅读全文
摘要:Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. 该题是要求合并两
阅读全文
摘要:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 这道题如果有第21题 合并两个链表的基础就会比较容易,具体合并链表的时候有两种思路 (1)如果k个li
阅读全文
摘要:Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array whic
阅读全文
摘要:Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers.
阅读全文
摘要:Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree: All root-to-leaf paths are:
阅读全文
摘要:112题目如下: Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the giv
阅读全文
摘要:Implement atoi to convert a string to an integer. 题目分析: 题目本身很简单就是将一个字符串转化成一个整数,但是由于字符串的千差万别,导致在实现的时候细节非常多。需要注意的有以下一些: 1.字符串可能由一些空格开始,然后遇到一个正号或者负号,然后是正
阅读全文
摘要:leetcode网站原题如下:给一个非负数组,开始位置是下标为0的元素,数组的元素代表当前位置最多向前行进多少个位置,判断是否能到达数组的最后一个位置,能就回复true,不能就回复false. Given an array of non-negative integers, you are init
阅读全文
摘要:题目:算出二叉树的最大深度 解决方案:(1)BFS (2)DFS (1)BFS 一层一层往下搜索,一直找到最深的点,这里由于节点的val是没有用的,所以可以用来存储当前节点的深度,然后注意指针一定要初始化,不然在leetcode里可能会出现runtime error /** * Definition
阅读全文

浙公网安备 33010602011771号