
算法
sjk1996
好好学习
展开
-
2. Add Two Numbers
【题目】You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and re...原创 2018-08-07 10:09:28 · 334 阅读 · 0 评论 -
1. Two Sum
【题目】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 not use the...原创 2018-08-07 09:16:49 · 377 阅读 · 0 评论 -
22. Generate Parentheses
【题目】Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. 【举例】For example, given n = 3, a solution set is:[ "((()))", "(()())", "(())...原创 2018-08-06 11:20:04 · 238 阅读 · 0 评论 -
5. 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 1:Input: "babad"Output: "bab"Note: "aba" is also a vali...原创 2018-08-05 10:56:59 · 191 阅读 · 0 评论 -
11. Container With Most Water
【题目】Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Fi...原创 2018-08-04 10:22:20 · 188 阅读 · 0 评论 -
14. Longest Common Prefix
【题目】Write a function to find the longest common prefix string amongst an array of strings.If there is no common prefix, return an empty string "".【举例】Example 1:Input: ["flower","flow","flig...原创 2018-08-04 09:51:35 · 157 阅读 · 0 评论 -
16. 3Sum Closest
【题目】Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each input ...原创 2018-08-04 09:34:57 · 224 阅读 · 0 评论 -
15. 3Sum
【题目】Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.【注意】The solution set must not...原创 2018-08-03 11:09:46 · 261 阅读 · 0 评论 -
9. Palindrome Number
【描述】Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.【举例】Example 1:Input: 121Output: trueExample 2:Input: -121Output...原创 2018-07-31 12:06:12 · 796 阅读 · 0 评论 -
7. Reverse Integer
【描述】Given a 32-bit signed integer, reverse digits of an integer.【举例】Example 1:Input: 123Output: 321Example 2:Input: -123Output: -321Example 3:Input: 120Output: 21Note:Assum...原创 2018-07-30 10:21:08 · 183 阅读 · 0 评论 -
6. 锯齿形转换
[题目]字符串“PAYPALISHIRING”是在给定的行数上以之字形书写的(您可能想要以固定字体显示此模式,以提高可读性):P A H NA P L S I I GY I R然后一行一行一行地读:“PAHNAPLSIIGYIR”编写一个字符串代码,在给定行数的情况下进行转换:string convert(string s, int numRows)...原创 2018-07-29 10:33:03 · 453 阅读 · 0 评论 -
3. 确定字符串最长不重复子串的长度
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 is "b", wit...原创 2018-07-28 10:23:17 · 342 阅读 · 0 评论 -
插入排序—直接插入排序(Straight Insertion Sort)
基本思想:将一个记录插入到已排序好的有序表中,从而得到一个新,记录数增1的有序表。即:先将序列的第1个记录看成是一个有序的子序列,然后从第2个记录逐个进行插入,直至整个序列有序为止。要点:设立哨兵,作为临时存储和判断数组边界之用。直接插入排序示例:如果碰见一个和插入元素相等的,那么插入元素把想插入的元素放在相等元素的后面。所以,相等元素的前后顺序没有改变,从原无序序列出去的顺序就是排好序后的顺序,...原创 2018-06-10 10:54:33 · 319 阅读 · 0 评论 -
二叉树的深度优先遍历和广度优先遍历
package 基础算法;import java.util.LinkedList;import java.util.Queue;public class BinaryTreeTraverseTest { public static void main(String[] args) { BinarySortTree<Integer&...原创 2018-04-24 20:41:51 · 185 阅读 · 0 评论 -
如何判断链表有环并确定环的起点
首先我们让fast指针(一次走两步)和slow指针(一次走一步)同时指向头结点, 然后同时向后移动。如果链表是一个整环的话, slow指针走一圈的时候与fast指针重合, 此时fast走了两圈。 如果链表不是一个整环, slow指针没来得及走一圈就会与fast指针重合, 此时fast指针比slow指针多走了n圈(n>=1)假设两个指针第一次重合, slow走了S, fast就走了2S, 设圈...原创 2018-04-18 10:58:54 · 1091 阅读 · 0 评论