算法
chengyunyi123
滴水穿石,非一日之功
展开
-
LeetCode - linked-list-cycle-ii
题目描述: Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull. Follow up: Can you solve it without using extra space? 时间限制:1秒 空间限制:32768K 思路: 1)使用快慢指原创 2017-08-08 13:30:04 · 201 阅读 · 0 评论 -
LeetCode- Three Sum
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原创 2017-08-28 17:32:46 · 323 阅读 · 0 评论 -
Leetcode - Longest Palindromic Substring
Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. Example: Input: “babad” Output: “bab” Note: “aba” is also a valid ans原创 2017-08-23 15:35:43 · 349 阅读 · 0 评论 -
LeetCode - Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. Examples: Given “abcabcbb”, the answer is “abc”, which the length is 3. Given “bbbbb”, the answer i原创 2017-08-10 12:39:58 · 342 阅读 · 0 评论 -
LeetCode - Two Sum
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, and you may no原创 2017-08-09 10:14:54 · 294 阅读 · 0 评论 -
LeetCode - Word-Break
题目描述 Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words. For example, given s =”leetcode”, di原创 2017-08-08 16:48:38 · 229 阅读 · 0 评论 -
LeetCode - Binary-Tree-Postorder-Traversal
题目描述 Given a binary tree, return the postorder traversal of its nodes’ values. For example: Given binary tree{1,#,2,3}, 1 \ 2 / 3 return[3,2,1]. /** * D原创 2017-08-08 15:06:43 · 183 阅读 · 0 评论 -
LeetCode - Binary-Tree-Preorder-Traversal
题目描述 Given a binary tree, return the preorder traversal of its nodes’ values. For example: Given binary tree{1,#,2,3}, 1 \ 2 / 3 return[1,2,3]. Note: Re原创 2017-08-08 15:05:12 · 196 阅读 · 0 评论 -
剑指Offer面试题33
这个解法最精华的就是自定义一个排序规则,给出两个数字m和n,我们需要确定一个规则判断m和n哪个应该排在前面,而不是仅仅比较两个数字的值。根据题目要求,两个数字能拼接成mn和nm.如果mnpackage test;import java.util.ArrayList; import java.util.Collections; import java.util.Comparator;/** * 剑指原创 2016-11-15 15:19:25 · 511 阅读 · 0 评论 -
剑指Offer面试题37
这题的难点在于理解单链表中如果有第一个公共节点,那么其后的所有节点都重合。/* public class ListNode { int val; ListNode next = null; ListNode(int val) { this.val = val; } }*/ public class Solution { public ListNo原创 2016-11-18 15:42:55 · 321 阅读 · 0 评论 -
七大排序算法
七大排序分类:插入排序:直接插入排序(稳定) --> 希尔排序(不稳定); 选择排序:简单选择排序(稳定) --> 堆排序(不稳定); 交换排序:冒泡排序(稳定) --> 快速排序(不稳定); 归并排序。 直接插入排序 时间复杂度 : O(n^2) 算法稳定性:稳定算法流程: 1)初始时,a[0]自成一个有序区,无序区为a[1,…,n-1],令i = 1;得到一个新的记录数增1的有序原创 2016-11-02 10:50:57 · 249 阅读 · 0 评论 -
剑指offer面试题[58]-二叉树的下一个结点
题目描述给定一个二叉树和其中的一个结点,请找出中序遍历顺序的下一个结点并且返回。注意,树中的结点不仅包含左右子结点,同时包含指向父结点的指针。思路:首先知道中序遍历的规则是:左根右,然后作图结合图,我们可发现分成两大类:1、有右子树的,那么下个结点就是右子树最左边的点;(eg:D,B,E,A,C,G) 2、没有右子树的,也可以分成两类: a)是父结点左孩子(eg:N,I,L) ,那么父结点就是下一原创 2017-10-25 09:22:53 · 250 阅读 · 0 评论