自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

一只奋斗的小菜鸟的博客

我将于茫茫人海中访我唯一灵魂之伴侣;得之,我幸;不得,我命 。

  • 博客(56)
  • 问答 (1)
  • 收藏
  • 关注

原创 剑指offer-----调整数组顺序使奇数位于偶数前面

/** * 剑指offer面试题14: 调整数组顺序使奇数位于偶数前面 * * 题目:输入一个整数数组,实现一个函数来调整该数组中数字的顺序,使得所有奇数位于数组的前半部分,所有 * 偶数位于数组的后半部分。 * * 思路1:我们可以维护两个指针,第一个指针初始化时指向数组的第一个数字,它只向后移动;第二个指针初始化时指向数组的最后一个数字, * 它指向前移动。在两个指针相...

2018-08-10 13:35:49 436

原创 剑指offer-----在O(1)时间删除链表结点

/** * 剑指offer面试题13:在O(1)时间删除链表结点 * * 题目:给定单向链表的头指针和一个结点指针,定义一个函数在O(1)时间删除该结点。 * * 解题思路:由于给定的是单向链表,正常删除链表的时间复杂度是查找链表的时间复杂度即O(n), * 如果要求在O(1)时间复杂度内删除节点,通过遍历链表找到该节点的上一节点和下一节点的方法 * 是行不通了。所以实现的思路...

2018-08-10 10:58:28 313

原创 剑指offer-----打印1到最大的n位数

import java.util.Arrays;/** * 剑指offer面试题12:打印1到最大的n位数 * * 题目:输入数字n,按顺序打印出从1最大的n位十进制数。比如输入3,则打印出1,2,3一直到最大的3位数即999. * * 考查:解决大数处理问题---可以使用字符串或者数组来处理大数问题 * * 思路1:在字符串或者数组模拟数字加法的解法 * 思路2:把问...

2018-08-10 09:47:05 320

原创 剑指offer-----数值的整数次方

/** * 剑指offer面试题11:数值的整数次方 * * 题目:实现函数double power(double base,int exponent),求base的exponent次方。 * 不得使用库函数,同时不需要考虑大数问题. * * 特殊情况分析: * 1.底数为0,指数为负数的情况,无意义 * 2.指数为0,返回1 * 3.指数为负数,返回(1.0/(...

2018-08-07 09:35:14 223

原创 剑指offer-----二进制中1的个数

/** * 剑指offer面试题10:二进制中1的个数 * * 题目:请实现一个函数,输入一个整数,输出该数二进制表示中1的个数。例如把9表示成二进制是1001, * 有2位是1。因此如果输入9,该函数输出2. * * 思路1:首先把n和1做与运算,判断n的最低位是不是1.接着把1左移一位得到2,再和n做与运算,就能判断n的次位是不是1.... * 这样反复左移,每次就能判断n...

2018-08-06 10:15:31 181

原创 剑指offer-----斐波那契数列

/** * 剑指offer面试题9:斐波那契数列 * * 题目:写入一个函数,输入n,求斐波那契数列的第n项。 * * 考察:递归,循环,时间复杂度的理解 * * 推荐方式:用循环来解 * * 应用1:一只青蛙一次可以跳上1级台阶,也可以跳上2级,求该青蛙跳上一个n级台阶总共有多少中跳法。 * * 相关题目:我们可以用2*1的小矩形横着或者竖着去覆盖更大的矩形。请...

2018-08-05 10:49:23 206

原创 剑指offer-----旋转数组的最小数字

/** * 剑指offer面试题8:旋转数组的最小数字 * * 题目:把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转。输入一个递增排序的数组的一个旋转, * 输出旋转数组的最小元素。例如数组{3,4,5,1,2}为{1,2,3,4,5}的一个旋转,该数组的最小值为1. * * 考查:二分查找的理解 * * 思路: 在排序数组中,可以使用二分查找法进行查找...

2018-08-04 20:37:49 168

原创 剑指offer-----用两个栈实现队列

import java.util.Stack;/** * 剑指offer面试题7:用两个栈实现队列 * * 题目:用两个栈实现一个队列。完成队列的Push和Pop操作。队列的元素为int类型。 * * 考查:对栈和队列的理解,栈是先进后出,队列是先进先出 * * 思路:第一准备两个栈用于实现队列分别为instack和outstack; * 第二当有新元...

2018-08-03 13:19:34 402

原创 剑指offer-----重构二叉树

/** * 剑指offer面试题6:重构二叉树 * * 题目:输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树。假设输入的前序遍历和中序遍历结果中都不含重复的数字。 * * 思路:根据前序遍历序列的第一个数字创建根结点,接下来在中序遍历序列中找到根结点的位置,这样就可以确定左、右子树结点的 * 数量。在前序遍历和中序遍历的序列中划分左、右子树结点的值,然后递归调用,分别构...

2018-08-02 20:15:53 150

原创 剑指offer-----从尾到头打印链表

import java.util.Stack;/** * 从尾到头打印链表 * 题目:输入一个链表的头结点,从尾到头反过来打印出每个结点的值。等价于反转链表 * * 考察:单链表的理解,对循环、递归和栈3个相互关联的概念理解 * * 考虑:是否允许改变链表的结构 */public class LinkListReverse { //使用栈结构存储结点值。-------...

2018-08-02 10:07:11 124

原创 剑指offer-----二维数组中的查找

/** * 二维数组中的查找 * * 题目:在一个二维数组中(每个一维数组长度相同),每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数, * 输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。 * * 解法思路1:因为二维数组每行都是递增顺序,那可以遍历每一行,利用二分查找,搜素目标值。时间复杂度为O(nlogn)...

2018-08-01 20:24:45 186

原创 剑指offer-----替换空格

/** * 替换空格 * 请实现一个函数,把字符串中的每个空格替换成"%20"。例如输入"we are happy",则输出"we%20are%20happy" * * 需要考虑1:替换字符串是否在原来的字符串上做替换,还是新开辟一个字符串做替换。 * 需要考虑2:在当前字符串替换,怎么替换才更有效率(不考虑java中的replaceAll方法) * * 解决1思路:直接调用S...

2018-08-01 10:02:26 110

转载 机器学习-----K-Means

聚类的定义    将物理或抽象对象的集合分成由类似的对象组成的多个类的过程被称为聚类。由聚类所生成的簇是一组数据对象的集合,这些对象与同一个簇中的对象彼此相似,与其他簇中的对象相异。“物以类聚,人以群分”,在自然科学和社会科学中,存在着大量的分类问题。聚类分析又称群分析,它是研究(样品或指标)分类问题的一种统计分析方法。聚类分析起源于分类学,但是聚类不等于分类。聚类与分类的不同在于,聚类所要求...

2018-07-30 09:45:15 309

原创 AdaBoost算法原理详解

Boosting提升算法    Boosting算法是将“弱学习算法”提升为“强学习算法”的过程,最具有代表性的是AdaBoost算法。Boosting提升算法思想:对于一个复杂任务来说,将多个专家的判断进行适当的综合所得出的判断,要比其中任何一个单独判断的好;相当于“三个臭皮匠顶个诸葛亮”。一般来说,提升方法就是从弱学习算法出发,反复学习,得到一系列弱分类器(基本分类器),组合这些弱分类器得到一...

2018-07-10 17:01:28 892

原创 Android-----Fragment动态添加和替换

/** * 添加一个Fragment * @param containerId * @param fragment * @param tag */ protected void addFragment(int containerId, Fragment fragment, String tag) { Fragment...

2018-03-01 19:47:10 1894

原创 Android-----解决EditText控件的自动弹出键盘的办法

1.如何一开始隐藏Edittext自动获取焦点的时候弹出软键盘 解决方法:在AndroidManifest中,相应的Activity中添加如下代码,可以达到隐藏软键盘android:windowSoftInputMode="stateHidden"2.如何在软键盘弹出的时候把布局向上顶,控件乱套,解决方法如下getWindow().setSoftInputMode(WindowManager.La

2018-01-18 15:37:46 1471

原创 LeetCode ----- 48.Rotate Image

You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Note:You have to rotate the image in-place, which means you have to modify the input 2D matr

2018-01-10 19:38:11 206

原创 LeetCode----- 40.Combination Sum II

Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may only be used once in the combina

2018-01-08 20:55:16 174

原创 LeetCode----- 39. Combination Sum

Given a set of candidate numbers (C) (without duplicates) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen

2018-01-05 21:54:20 281

原创 LeetCode----- 35.Search Insert Position

Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.

2018-01-03 19:49:51 175

原创 LeetCode----- 34.Search for a Range

Given an array of integers 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

2018-01-02 20:32:48 190

原创 Android-----崩溃的log日志捕捉

当用户在使用程序的时候,遇到程序崩溃,但是程序员又不知道出现的是啥原因。解决方法:可以在自己自定义的Application中捕捉全局异常,将它写入到本地文件中,再上传到自己的服务器上面。代码如下:public class MyApplication extends Application { @Override public void onCreate() { super.onCr

2017-12-08 15:16:01 697

原创 Android-----SharedPreences工具类

public class SharedPreUtil { private static SharedPreferences mSp = null; //缓存的config_sp.xml文件 private static final String CONFIG_SP ="config_sp"; private static SharedPreferences get

2017-12-08 11:19:46 279

原创 Java-----Semaphore信号量

一.Semaphore介绍Semaphore:字面意思是信号量,主要用来控制同时访问某个特定资源的操作数量或者某个操作的数量。二.Semaphore常用操作函数(1).构造函数:public Semaphore(int permits) public Semaphore(int permits, boolean fair) 第一个构造函数:permits指定允许许可的初始数量

2017-12-07 14:59:17 236

原创 Java----- ArrayList构造、add、remove、clear方法实现原理源码分析

一.ArrayList内部的实现方式ArrayList内部是通过Object[]实现的。二.源码分析:(1).构造方法 public ArrayList() { array = EmptyArray.OBJECT; } public ArrayList(int capacity) { if (capacity < 0)

2017-12-04 15:42:37 2793

原创 ScrollView与RecyclerView冲突及异常情况处理

昨天再写项目的时候,有一个布局需要ScrollView嵌套RecyclerView,效果展示的时候RecyclerView的滑动会出现卡顿的样子,ScrollView也滑动不流畅。产生的原因是ScrollView与RecyclerView冲突引起的。解决方法:先自定义LinearLayoutManager,重新测量;再自定义ScrollView,横向不拦截,竖向拦截;(1).自定义

2017-11-20 10:53:31 532

原创 LeetCode----- 31.Next Permutation

Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possib

2017-11-14 19:35:13 234

原创 LeetCode----- 27.Remove Element

Given an array and a value, remove all instances of that value in-place and return the new length.Do not allocate extra space for another array, you must do this by modifying the input array in-

2017-11-09 20:38:15 144

原创 LeetCode----- 26. Remove Duplicates from Sorted Array

Given a sorted array, 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

2017-11-08 20:34:30 141

原创 Android-----Viewpager加载不出Fragment数据的情况

原因:昨天再写ViewPager+fragment+RadioButton布局的时候,当点击第4个RadioButton切换到第四个fragment,然后再点击第一个RadioButton切换第一个fragment,再点击第4个RadioButton切换到第四个fragment的时候,fragment会加载不出数据的情况。       解决办法:因为ViewPager再加载页面的时候,每次都会

2017-10-31 08:52:35 1119

原创 LeetCode----- 86.Partition List

Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order of the nodes in each of

2017-10-27 09:07:11 211

原创 Leetcode----- 82.Remove Duplicates from Sorted List II

Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example,Given 1->2->3->3->4->4->5, return 1->2->5.Given 1->1-

2017-10-24 21:44:29 329

原创 LeetCode----- 83.Remove Duplicates from Sorted List

Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3.给定已排序好的链表,删除链表中所有的重复项,使

2017-10-24 19:48:15 166

原创 LeetCode----- 61. Rotate List

Given a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL.给定一个单链表,将单链表旋转到右边的k个位置,k为非负数。

2017-10-20 21:31:17 200

原创 LeetCode----- 24.Swap Nodes in Pairs

Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. Y

2017-10-17 20:03:36 212

原创 LeetCode----- 21.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.合并两个已经排序的链表,并将其作为一个新链表返回。新的链表应该通过拼接前两个链表的节点来完成。代码如下:

2017-10-16 20:24:32 192

原创 LeetCode----- 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 return

2017-10-16 08:32:00 230

原创 LeetCode----- 19.Remove Nth Node From End of List

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

2017-10-14 20:42:27 176

原创 LeetCode----- 12.Integer to Roman

Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.解题思路:直接对输入的num,直接求出各位上的数。public static String intToRoman(int num) { Map map = new

2017-10-13 21:07:17 219

原创 LeetCode----- 16.3Sum Closest

Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exact

2017-10-13 19:35:42 181

空空如也

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

TA关注的人

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