![](https://img-blog.csdnimg.cn/20201014180756923.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Leetcode
文章平均质量分 52
小圆酱
宾夕法尼亚大学
展开
-
Leetcode - 19. Remove Nth Node From End of List -Java
先计算链表总长度 len, 再减去 输入 n, 得到的就是要删除Node的位置,缺点无法 one pass, 时间: 16ms/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val =...原创 2018-06-15 03:13:50 · 139 阅读 · 0 评论 -
Leetcode - 3Sum Closest - Java
问题是需要找三个数字之和离target 最近的一组组合。 首先判断输入的数组是否有足够的数字提供组合,及num.length>=3。 同K sum 问题现将数组排序,同样固定一个数字,使用双指针去找另两个。定义两个变量,closet 和 re。 closet 用于更新现在离target最近的距离,re用于保存发现的最短距离target的sum值。 首先给closet赋最大值,然后每次发现 s...原创 2018-06-15 03:23:10 · 197 阅读 · 0 评论 -
Leetcode - 20. Valid Parentheses - Java
先进后出,使用堆栈处理. 缺点:速度慢。 12msStack stack = new Stack(); // 创建堆栈对象stack.push(item); // 把项压入栈顶stack.pop(item); //把项移除栈顶stack. empty(); //判断栈空 booleanstack.peek(); //查看栈顶而不移除,返回object 类型printStack(stack); //...原创 2018-06-15 15:00:56 · 154 阅读 · 0 评论 -
Leetcode - 28. Implement strStr() - Java
Implement strStr(). Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. Example 1: Input: haystack = “hello”, needle = “ll” Output: ...原创 2018-07-03 02:51:40 · 134 阅读 · 0 评论 -
Leetcode - 29. Divide Two Integers - Java
Given two integers dividend and divisor, divide two integers without using multiplication, division and mod operator. Return the quotient after dividing dividend by divisor. The integer divis...原创 2018-07-03 09:53:24 · 422 阅读 · 0 评论 -
Leetcode - 24. Swap Nodes in Pairs - Java
思想使用递归的方法,实现指针的位移。 使用两个指针,分别指向当前访问节点和当前访问节点的前一节点,这样方便我们调换,当前节点和当前节点的next节点的位置。需还要特别注意的是第一二个节点,因为此时,前一节点和当前节点都在head位置,那么此时的操作将不同于其他位置的操作,因为如果调换两个的位置,我们最后需要返回head,那么head的位置也将被调换,我们将丢掉一个节点,永远无法被...原创 2018-06-29 01:04:49 · 387 阅读 · 0 评论 -
Leetcode -167. Two Sum II - Input array is sorted - Java
HashmapOne solution is to use hashmap to quickly check whether we have seen (target - nums[i])if so, we return a new array with the index of (target - nums[i]) and nums[i]. (Be aware that, index ...原创 2018-08-21 09:03:05 · 219 阅读 · 0 评论