自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(35)
  • 收藏
  • 关注

原创 Pow(x, n)

Implement pow(x, n), which calculates x raised to the power n (xn).Example 1:Input: 2.00000, 10Output: 1024.00000Example 2:Input: 2.10000, 3Output: 9.26100Example 3:Input: 2.00000, -2Output: ...

2019-05-27 00:21:23 190

转载 Count and Say

The count-and-say sequence is the sequence of integers with the first five terms as following:1112112111112211 is read off as “one 1” or 11.11 is read off as “two 1s” or 21.21...

2019-05-22 20:24:07 179

原创 Find First and Last Position of Element in Sorted Array

Given an array of integers nums sorted in ascending order, find the starting and ending position of a given target value.Your algorithm’s runtime complexity must be in the order of O(log n).If the t...

2019-05-22 17:27:45 175

转载 Search in Rotated Sorted Array

Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]).You are given a target value to search. If found in...

2019-05-20 21:46:10 126

原创 Divide Two Integers

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 division shoul...

2019-05-20 21:02:34 128

原创 Implement strStr

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: 2Example 2:In...

2019-05-19 10:27:37 134

原创 Remove Duplicates from Sorted Array

Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this by modifyin...

2019-05-18 11:27:56 86

转载 Swap Nodes in Pairs

Given a linked list, swap every two adjacent nodes and return its head.You may not modify the values in the list’s nodes, only nodes itself may be changed.Example:Given 1->2->3->4, you sho...

2019-05-18 10:34:25 111

原创 Merge Two Sorted Lists

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.Example:Input: 1->2->4, 1->3->4Output: 1-&gt...

2019-05-17 00:11:43 87

原创 Valid Parentheses

Given a string containing just the characters ‘(’, ‘)’, ‘{’, ‘}’, ‘[’ and ‘]’, determine if the input string is valid.An input string is valid if:Open brackets must be closed by the same type of bra...

2019-05-16 23:20:22 79

原创 Remove Nth Node From End of List

Given a linked list, remove the n-th node from the end of list and return its head.Example:Given linked list: 1->2->3->4->5, and n = 2.After removing the second node from the end, the l...

2019-05-16 16:39:59 79

原创 Letter Combinations of a Phone Number

Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is give...

2019-05-16 10:53:07 97

原创 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 would ...

2019-05-15 23:12:59 98

转载 three sum

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.Note:The solution set must not contai...

2019-05-15 10:18:19 101

原创 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”,“flight”]Output: “fl...

2019-05-14 23:30:30 75

原创 IntegerToRoman

Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.Symbol ValueI 1V 5X 10L 50C 100D ...

2019-05-14 10:01:39 81

原创 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). Find two l...

2019-05-13 23:26:49 110

原创 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: falseExplanation...

2019-05-13 10:15:57 103

转载 String to Integer

Implement atoi which converts a string to an integer.The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this...

2019-05-13 09:53:29 109

原创 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:Assume we are dealing with an ...

2019-05-12 10:27:04 67

原创 Zigzag Conversion

The string “PAYPALISHIRING” is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H NA P L S I I G...

2019-05-11 23:55:54 71

原创 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 valid answer.Example ...

2019-05-11 11:06:13 90

原创 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 same e...

2019-05-10 20:54:32 95

原创 Longest Substring Without Repeating Characters(无重复最长子串)

Given a string, find the length of the longest substring without repeating characters.Example 1:Input: “abcabcbb”Output: 3Explanation: The answer is “abc”, with the length of 3.Example 2:Input: ...

2019-05-10 20:31:08 73

原创 Add two numbers

ou 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 return it...

2019-05-08 16:44:56 107

原创 剑指offer-面试题36:二叉搜索树与双向链表

题目:输入一颗二叉搜索树,将该二叉搜索树转换称一个排序的双向链表。要求不能创建任何新的节点,只能调整树中节点指针的指向。在二叉搜索树中,每一个节点都有一个指向其左节点和其右节点的指针,因此我们可以利用这两个指针。将指向其左节点的指针调整为链表中指向前一个节点的指针,将其指向右节点的指针调整为链表中指向后一个节点的指针。并且由于要求转换后的链表有序,因此我们可以采用二叉搜索树的中序遍历,然后对其指...

2019-05-03 20:57:16 235

原创 剑指offer-面试题54:二叉搜索树的第K大节点

题目:给定一颗二叉搜索树,请找出其中第K大的节点。核心思想:中序遍历如上图,中序遍历的结果位:2,3,4,5,6,7,8,则在该二叉搜索树中第3大的节点值为4.具体代码如下:public class Solution { int index = 0; TreeNode KthNode(TreeNode pRoot, int k) { if(pRo...

2019-05-03 20:29:17 284

原创 二叉排序树(二叉查找树、二叉搜索树)

什么是二叉查找树:根节点的值大于其左子树中任意一个节点的值,小于其右节点中任意一节点的值,这一规则适用于二叉查找树中的每一个节点。本文章重点来讨论一下关于二叉查找树删除节点的问题。有一下二叉查找树,如图:在删除节点的时候我们只需考虑一下三种情况:(1)要删除的节点是叶子结点,如图:(2)要删除的节点有左节点但是没有右节点,或者有右节点但是没有左节点,如图:(3)要删除的节点既有...

2019-05-03 00:16:08 108911 14

原创 赫夫曼树的构建

赫夫曼树:带权路径最小的二叉树public class HuffmanTree{ publlic class Node implements Comparable<Node > { int weight; Node left = null; Node right = null; pu...

2019-05-02 16:26:32 438

转载 剑指offer-面试题34:二叉树中和为某一值的路径

题目:输入一颗二叉树的跟节点和一个整数,打印出二叉树中结点值的和为输入整数的所有路径。路径定义为从树的根结点开始往下一直到叶结点所经过的结点形成一条路径。(注意: 在返回值的list中,数组长度大的数组靠前)public class TreeNode { int value = 0; TreeNode leftNode = null; TreeNode rightNod...

2019-05-02 16:06:41 92

转载 剑指offer:把二叉树按照之字形打印

题目:请实现一个函数按照之字形打印二叉树,即第一行按照从左到右的顺序打印,第二层按照从右至左的顺序打印,第三行按照从左到右的顺序打印,其他行以此类推。实现代码如下:public static ArrayList<ArrayList<Integer> > PrintByZhi(TreeNode pRoot) { ArrayList<ArrayList<In...

2019-05-01 23:43:38 81

原创 剑指offer:把二叉树打印成多行

题目:把二叉树打印成多行,即每一层打印为一行代码如下://非递归public ArrayList<ArrayList<Integer>> printLevel(TreeNode root){ if(root == null) return null; ArrayList<ArrayList<Integer>> arrs =...

2019-05-01 22:42:53 149

原创 面试题8:二叉树的下一个节点

题目:给定一棵二叉树和其中的一个节点,如何找出中序遍历序列的下一个节点?树中的节点除了有两个分别指向左、右子节点的指针,还有一个指向父节点的指针。如下图所示:这颗二叉树的中序遍历序列是:d,b,h,e,i,a,f,c,g,在本题目中,我们只需考虑三种情况:(1)如果一个节点有右子树,那么它的下一个节点是该节点右子树最左子节点,如上图中的b节点,它的下一个节点即是h;(2)如果一个节点没有...

2019-05-01 20:14:52 109

原创 8中排序算法及其优化:采用Java语言描述

1、 冒泡排序及其优化核心思想: 通过每一轮的比较,把较大的数字放在末尾,每一轮比较完之后,下一轮的比较的次数为该数组的长度减去循环次数再减一。举例: 有以下数组 5 4 6 7 1 9 8第一次循环:第一趟比较:4 5 6 7 1 8 9第二趟比较:4 5 6 1 7 8 9第三趟比较:4 5 1 6 7 8 9第四、五、六趟比较结果与第三趟一样第二次循环:第一趟比较:4 1...

2019-04-27 19:49:37 174

原创 创建堆以及实现堆排序

什么是堆???可以把堆看成是一颗完全二叉树,并且这颗完全二叉树有一个特点:根节点比其左右叶子结点的值都大或者都小。如果每一个根节点比其左右叶子节点的值都大,则称之为大顶堆,反之就称为小顶堆。这一规则必须在完全二叉树的任一子树都满足。完全二叉树的特点:设根节点的索引值为index;(1)左节点的索引值为 2indexe +1;(2)右节点的索引值为 2index+2;(3)其父节点的值为(...

2019-04-27 10:23:35 465

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除