leetcode 系列
文章平均质量分 60
AndrewDengpf
这个作者很懒,什么都没留下…
展开
-
Longest string
/** * Created by kobe73er on 16/12/9. * * Examples: * * Given "abcabcbb", the answer is "abc", which the length is 3. * * Given "bbbbb", the answer is "b", with the length of 1. * * Given原创 2016-12-15 21:20:36 · 261 阅读 · 0 评论 -
二叉树的广度优先遍历
package com.dengpf.BinaryTreeLevelOrderTraversal;import java.util.ArrayList;import java.util.LinkedList;import java.util.List;import java.util.Queue;/** * Definition for a binary tree node. *原创 2016-12-24 16:41:17 · 353 阅读 · 0 评论 -
计算一个二叉树的深度
// 获取最大深度 public static int getMaxDepth(TreeNode root) { if (root == null) return 0; else { int left = getMaxDepth(root.left); int right = getMa原创 2016-12-24 16:08:31 · 848 阅读 · 0 评论 -
LeetCode Linked List Cycle II 计算带环的链表的起点
图:设:链表头是X,环的第一个节点是Y,slow和fast第一次的交点是Z。各段的长度分别是a,b,c,如图所示。环的长度是L。slow和fast的速度分别是qs,qf。第一次相遇时slow走过的距离:a+b,fast走过的距离:a+b+c+b。因为fast的速度是slow的两倍,所以fast走的距离是slow的两倍,有 2(a+b) =原创 2016-12-24 14:49:25 · 788 阅读 · 0 评论 -
3Sum
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note: The solution set must not contain原创 2016-12-17 16:53:32 · 260 阅读 · 0 评论 -
指定数组的下标,如果数组元素等于指定值
Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution.Example:Given nums = [2, 7, 11,原创 2016-12-17 13:15:45 · 573 阅读 · 0 评论 -
判断是否是回文数字
package com.dengpf.HuiWen;/** * Created by kobe73er on 16/12/17. */public class Solution { public boolean isPalindrome(int x) { String result = String.valueOf(x); int start原创 2016-12-17 12:59:32 · 378 阅读 · 0 评论 -
Implement atoi to convert a string to an integer.
package com.dengpf.StringToInteger;/** * Created by kobe73er on 16/12/17. */public class Solution { public int myAtoi(String str) { if (str == null || str.length() < 1) re原创 2016-12-17 11:45:25 · 625 阅读 · 0 评论 -
自己实现LRUCache
LRU的典型实现是double linked list + hash map。 双向链表根据每个节点最近被访问的时间有序存储,最近被访问的节点存储在表头,最近没有被访问的节点存储的表尾,存储依据是因为:最近被访问的节点在接下来的一段时间仍有很大的概率被再次访问到。 哈希表的作用是用来提高查找效率,如果不使用哈希表,则查找一个节点的时间复杂度是O(n),而使用了哈希表,则每个节点的查找时间复杂度为O原创 2016-12-17 09:27:08 · 571 阅读 · 0 评论 -
Add two numbers
package com.dengpf.AddTwoNumbers;import org.w3c.dom.ls.LSException;import java.util.ArrayList;import java.util.LinkedList;/** * Created by kobe73er on 16/12/9. * * /** * Definition for sin原创 2016-12-15 21:18:27 · 372 阅读 · 0 评论 -
合并两个有序链表
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.Subscribe to see which companies asked this questio原创 2016-12-20 16:16:20 · 278 阅读 · 0 评论