2018年3月14日

指针和引用的区别

摘要: 1、指针是存放变量地址的一个变量,指向内存的一个存储单元,在逻辑上是独立的,可以被改变,包括其所指向的地址的改变和其指向的地址中所存放的数据的改变。引用是其所引用的变量的一个别名,与其所引用的变量实质上是同一个东西,在逻辑上不是独立的,它的存在具有依附性,所以引用必须在一开始就被初始化,而且其引用的 阅读全文

posted @ 2018-03-14 12:37 lina2014 阅读(120) 评论(0) 推荐(0) 编辑

2018年3月12日

new与malloc区别

摘要: 1、new分配内存时会按照数据类型计算需要分配内存的大小,malloc分配内存时是按照指定的大小分配的;2、new不仅分配一段内存,而且会调用构造函数,malloc不会调用构造函数;之前看到过一个题说int* p = new int与int* p = new int()的区别,因为int属于C++内 阅读全文

posted @ 2018-03-12 23:39 lina2014 阅读(153) 评论(0) 推荐(0) 编辑

2018年3月11日

016 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. 阅读全文

posted @ 2018-03-11 21:39 lina2014 阅读(118) 评论(0) 推荐(0) 编辑

排序算法

摘要: 排序算法总结:插入排序:直接插入排序,二分(折半)插入排序,希尔排序交换排序:冒泡排序,快速排序选择排序:简单选择排序,堆排序归并排序基数排序计数排序 1、插入排序 (1)直接插入排序 Java实现: package com.mian.sort; public class InsertSort { 阅读全文

posted @ 2018-03-11 11:56 lina2014 阅读(192) 评论(0) 推荐(0) 编辑

2018年3月10日

面试题—小算法20题

摘要: 1、IP转换成整数及整数转换成IP Java实现: package com.mian.demo; public class IpToInt { public static void main(String[] args) { String ip="192.168.12.90"; int ipInt= 阅读全文

posted @ 2018-03-10 23:30 lina2014 阅读(281) 评论(0) 推荐(0) 编辑

008 String to Integer (atoi) 字符串转换为整数

摘要: 详见:https://leetcode.com/problems/string-to-integer-atoi/description/ 实现语言:Java 实现语言:C++ 参考:http://www.cnblogs.com/grandyang/p/4125537.html 阅读全文

posted @ 2018-03-10 21:26 lina2014 阅读(116) 评论(0) 推荐(0) 编辑

LeetCode 233 Number of Digit One 某一范围内的整数包含1的数量

摘要: Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n.For example:Given n = 13,Return 6 阅读全文

posted @ 2018-03-10 20:27 lina2014 阅读(128) 评论(0) 推荐(0) 编辑

KMP算法

摘要: 给定一个主串(以 S 代替)和模式串(以 P 代替),要求找出 P 在 S 中出现的位置,此即串的模式匹配问题。 1、暴力匹配,时间复杂度为 O(nm),其中 n 为 S 的长度,m 为 P 的长度。 2、KMP算法 KMP算法的时间复杂度还是很稳定的。平均时间复杂度为 Θ(m+n)。最好时间复杂度 阅读全文

posted @ 2018-03-10 16:03 lina2014 阅读(143) 评论(0) 推荐(0) 编辑

009 Palindrome Number 判断一个正整数是否是回文数

摘要: 详见:https://leetcode.com/problems/palindrome-number/description/ 实现语言:Java 方法一: 方法二: 实现语言:C++ 方法一: 方法二: 阅读全文

posted @ 2018-03-10 15:36 lina2014 阅读(141) 评论(0) 推荐(0) 编辑

2018年3月9日

LeetCode 260 Single Number III 数组中除了两个数外,其他的数都出现了两次,找出这两个只出现一次的数

摘要: Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements 阅读全文

posted @ 2018-03-09 22:45 lina2014 阅读(150) 评论(0) 推荐(0) 编辑

导航