TinaCristal's Blog


  • Home

  • Tags

  • Categories

  • Archives

  • Search

L1-恢复旋转排序数组

Posted on 2018-05-18 | In LintCode

题目描述:

给定一个旋转排序数组,在原地恢复其排序。

什么是旋转数组?

比如,原始数组为[1,2,3,4], 则其旋转数组可以是[1,2,3,4], [2,3,4,1], [3,4,1,2], [4,1,2,3]

挑战:使用O(1)的额外空间和O(n)时间复杂度

Read more »

L1-在二叉查找树中插入节点

Posted on 2018-05-18 | In LintCode

描述
给定一棵二叉查找树和一个新的树节点,将节点插入到树中。

你需要保证该树仍然是一棵二叉查找树。

样例
给出如下一棵二叉查找树,在插入节点6之后这棵二叉查找树可以是这样的:

2 2
/ \ / \
1 4 –> 1 4
/ / \
3 3 6

挑战
能否不使用递归?

Read more »

L1-落单的数

Posted on 2018-05-18 | In LintCode

描述
给出2*n + 1 个的数字,除其中一个数字之外其他每个数字均出现两次,找到这个数字。
样例
给出 [1,2,2,1,3,4,3],返回 4

Read more »

html+css学习笔记(三)

Posted on 2018-05-17 | In web

常用标签及基本样式设置

1)标题

h1 一级标题 主标题,h2 副标题,h3,h4···字体依次往下减小

2)段落标签p

段落标签<p></p>,用来创建段落
Read more »

html+css学习笔记(二)

Posted on 2018-05-17 | In web

单选 复选框的使用

Read more »

L1-中位数

Posted on 2018-05-17 | In LintCode

问题描述:
给定一个未排序的整数数组,找到其中位数。
中位数是排序后数组的中间值,如果数组的个数是偶数个,则返回排序后数组的第N/2个数

思路一:
可以使用快速排序将数组排好序,然后返回中位数,这样做的时间复杂度是O(nlogn).

思路二:
使用“折半的快速排序”。就是每一次只对一边的数组进行排序。

Read more »

复习快排算法

Posted on 2018-05-17 | In 复习

基础知识还是要经常复习的!用的时候又有点忘了,特来复习一下。

网上快排大概有两种写法 不过思想差不多

一种是把第一个元素作为基准,先从右向左扫描,替换数组元素的值,最后把基准赋给i=j相遇时位置的值

另一种是往左移,往右移找出比基准大和往左移比基准小的元素交换位置,如果下标i<j的话,就交换两个元素,如果i=j的话,就把这个位置数组和元素的值和基准交换

Read more »

L1-二叉树层序遍历

Posted on 2018-05-16 | In LintCode

给出一棵二叉树,返回其节点值的层次遍历(逐层从左往右访问)

样例
给一棵二叉树 {3,9,20,#,#,15,7} :

3
/ \
9 20
/ \
15 7
返回他的分层遍历结果:

[
[3],
[9,20],
[15,7]
]

Read more »

L1-二叉树遍历(先,中,后)

Posted on 2018-05-14 | In LintCode

先序遍历 递归

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public class Solution {
public void preOrder(TreeNode root,List<Integer> res){
if(root==null) return;
res.add(root.val);
preOrder(root.left,res);
preOrder(root.right,res);
}
public List<Integer> preorderTraversal(TreeNode root) {
// write your code here
List<Integer> res = new ArrayList<>();
preOrder(root, res);
return res;
}

}
Read more »

L1-搜索插入位置

Posted on 2018-05-14 | In LintCode

描述
给定一个排序数组和一个目标值,如果在数组中找到目标值则返回索引。如果没有,返回到它将会被按顺序插入的位置。

你可以假设在数组中无重复元素。

Read more »
1…394041…45

TinaCristal

443 posts
57 categories
55 tags
GitHub E-Mail
© 2020 TinaCristal
Powered by Hexo
|
Theme — NexT.Mist v5.1.4