2018-01-17 Vaniot
2014-04-29 veryyoung
题目链接: http://oj.leetcode.com/problems/two-sum/ 题目内容: Given an array of integers, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2. Please note that your return 继续阅读 »
2016-07-01 YongHao Hu
C++
344. Reverse String Write a function that takes a string as input and returns the string reversed. Example: Given s = "hello", return "olleh". 继续阅读 »
2015-12-13 MoreFreeze
I have trained my algorithm on leetcode a period of time. Today, I will explain my solution about Minimum Height Trees. My solution beat ~95% against others but it is hard to explain what is I do. Please allow me to introduce the solution from easy to hard. If you only need the last solution, jump to 继续阅读 »
2016-10-10 craneyuan
基本问题 如何将单链表反转? 单链表结构定义 ``` java /** 单链表定义 * * @author: crane-yuan * @date: 2016-9-17 下午12:11:13 */ public class ListNode { public int val; public ListNode next; public ListNode(int x) { val = x; } } ``` more 算法实现 java /** 单链表反转 * * @param head * @return ListNode */ public static ListNode rever 继续阅读 »
2014-09-11 veryyoung
书籍整理: 程序员面试金典(第5版).pdf http://vdisk.weibo.com/s/D2zXXYpTKPKx 程序员编程艺术— 面试和算法心得pdf版 http://url.cn/M3vj4Z 刷题oj: leetcode http://oj.leetcode.com/problems/ 刷剑指offer http://ac.jobdu.com/hhtproblems.php# Java 内存区域和GC机制 http://www.cnblogs.com/zhguang/p/3257367.html#introduction http://www.ibm.com/developerworks/cn/ja 继续阅读 »
2016-06-06 craneyuan
Question Given a linked list, remove the nth node from the end of list and return its head. For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the linked list becomes 1->2->3->5. Note: Given n will always be valid. Try to do this in one pass. 解说 这道题的意思是,如何反向删 继续阅读 »
2016-10-12 craneyuan
基本问题 如何删除单链表中的倒数第n个节点? 常规解法 先遍历一遍单链表,计算出单链表的长度,然后,从单链表头部删除指定的节点。 more 代码实现 ``` java /** 删除单链表倒数第n个节点,常规解法. * * @param head * @param n * @return ListNode */ public static ListNode removeNthFromEnd(ListNode head, int n) { if(head == null) { return null ; } //get length of list ListNode p 继续阅读 »
2016-05-06 craneyuan
Question 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, 15], target = 9, Because nums[0] + nums[1] = 2 + 7 = 9, return [0, 1]. UPDATE (2016/2/13): The return forma 继续阅读 »
2016-09-16 craneyuan
题目描述 给定一个已排序的数组,去除数组中的重复元素,只保留一个重复的元素,并且返回新的数组长度。 要求: 不要给数组分配额外的空间,你必须使用常量的内存大小进行原地操作。 例如: 给出数组A=[1,1,2],你的函数调用之后必须返回长度length=2,并且A现在变成[1,2]。 输入 一个已排序的数组,例如[1,1,2]。 输出 返回数组新的长度,例如length=2。 快慢指针法 设置fast指针遍历数组,slow指针指向不重复元素的下一位。 more java public static int removeDuplicates(int[] nums) { if (nums.length < 1) 继续阅读 »