leetCode练习题】的更多相关文章

Permutation Sequence The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the permutations in order,We get the following sequence (ie, for n = 3): "123" "132" "213" "231" &q…
Leetcode练习题Remove Element Question: 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 array, you must do this by modifying the input array in-place with…
1 Arrays PS:Arrays位于java.util包下 int binarySearch(type[] a, type key); 使用二分法查询 key 元素在 a 数组中的索引,如果数组不包含这个值,则返回负数.使用前要求这个数组是升序排列,才能得到正确结果. int binarySearch(type[] a, int fromIndex, int toIndex, type key); 和上面类似,但是只从 fromIndex 到 toIndex 范围内找元素,一样要求数组是升序…
Remove Duplicates from Sorted List II Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. For example, Given 1->2->3->3->4->4->5, return 1->2->5. Given 1-&…
Recover Binary Search Tree Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing its structure. 互换二叉搜索树中两个位置错误的节点. 思路: 预设三个指针pre,p1,p2.p1用来指向第一个出错的节点,p2用来指向第二个出错的节点. 出错情况有两种,即p1和p2相邻,p1和p2不相邻. 中序遍历此二叉树,用…
Valid Palindrome Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For example,"A man, a plan, a canal: Panama" is a palindrome."race a car" is not a palindrome. Note:Have you…
Pow(x, n) Implement pow(x, n). 计算x的n次方. 解题思路: 考虑到n的值会很大,而且可为正可为负可为0,所以掉渣天的方法就是用递归了. 对了,这题也在<剑指offer>里面有提到,是面试题11:数值的整数次方.可以书里给的递归代码在n为负数的情况下是错误的……他没有考虑到n为奇数时,n是正数和n是负数的情况是不一样的. 具体参考这哥们的答案. 这里我摘抄下来,方便以后查询. double pow(double x, int n) { ) return 1.0;…
Combination Sum 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 repeated number may be chosen from C unlimited number of times. Note: All numbers (includi…
Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. 和上一题对应,求二叉树的最小深度. 解题思路: 参考上一题Maximun Depth of Binary Tree中最后那…
Maximum Depth of Binary Tree Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. 求二叉树的高度,即从根节点到叶节点上所有节点的数量. 解题思路: 这题是难度系数1,频率1的题目……用到的知识点是二叉树D…