自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 LeetCode: Regular Expression Matching

Implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the entire input st

2015-10-03 11:11:30 1067

原创 POJ: Exponentiation

DescriptionProblems involving the computation of exact values of very large magnitude and precision are common. For example, the computation of the national debt is a taxing experience for many co

2015-10-02 16:57:48 2856

原创 Substring with Concatenation of All Words——解题报告(窗口移动法)

【题目】You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in wordsexactly

2015-05-21 21:44:53 2006

原创 正则表达式的简单梳理

这篇博文我们按照每一种正则表达式符号来整理。1)行首定位符“^”:匹配行首的字符#-----------------------------/chapter8/ex8-2.sh------------------#! /bin/bash#列出/etc目录中的以字母po开头的文件str=`ls /etc | grep "^po"`echo "$str"注意:str变量的赋值,

2015-05-21 10:16:29 1307

原创 awk中遍历数组的2种方式

awk中数组比较随意,同一个数组中的元素不一定要相同类型,而且数组下表可以是数字也可以是字符。    遍历数组有两种方式:1. 类似于C++的方式#-----------------------------/chapter11/ex11-30.sh------------------#! /bin/awk -fBEGIN { #定义数组 stu[1]="200

2015-05-20 16:20:38 14463

原创 awk中的常用的字符串函数和数学函数

总结awk中常用的字符串函数和数学函数如下表:具体使用方法在实践中自行体会~

2015-05-20 16:05:33 1195

原创 awk中支持的运算符

awk中支持非常多的运算符,比shell脚本中要方便的多。注意点:这些运算符两边可以有空格,也可以不加,格式比较随意。另外,如果awk的运行方式是vi一个shell脚本,并且声明#! /bin/awk -f编辑器的话,那么我们需要chmod脚本文件为+x,然后再使用./脚本文件的形式执行awk程序,不可直接使用sh来执行。

2015-05-20 10:51:37 1834

原创 awk中的变量

awk中的变量定义非常简单,只需要给出一个变量名并且赋予适当的值即可。    awk中的常规变量分为两种类型:字符串和数值。无需指定变量类型,awk会根据变量所处的环境自动判断。如果没有指定值,数值类型的变量默认等于0,字符串类型的变量默认为空。    awk中的系统内置变量总结如下,有一点要事先说明:awk说明中,记录表示一个样本,字段表示特征。

2015-05-20 08:32:06 2043

原创 awk中的模式匹配

awk中的模式匹配在awk程序命令中非常重要,它决定着被处理数据文件中到底哪一行需要处理,并且做出什么样的处理。    首先,我们先看awk命令的基本语法:awk pattern { actions }   注意:pattern就是指的匹配模式,大括号外加两端空格的是处理动作。    上面awk后面的匹配模式和处理行为至少得有一个,不能两个同时缺失。例如,上篇博文中awk { pr

2015-05-20 07:31:37 9618

原创 执行awk程序的3种方式

awk是Linux系统中一种强大的数据处理工具,执行awk程序有3种方式。介绍如下:1. 命令行方式    语法形式:awk ' awk程序语句' 被处理文件名2. 执行awk脚本方式    语法形式:awk -f awk脚本文件名 被处理文件名    注意:必须要先vi新建一个awk脚本文件,以.awk结尾,里面编辑awk程序。 

2015-05-19 21:28:21 6292 3

原创 面试题中自增自减类型题目的解题技巧

在面试中,我们经常被问有关于自增自减的题目,这样的题目简单易懂,便于检验面试者的编程基本功,楼主在百度实习面试中就被问到。现在总结一下解题技巧:    对于以下,有int x = 5, y = 6, z;    题目1:z = ++x + y++;    题目2:z = ++x + x++;    题目3:x = ++x + x++;    对于上面的三道题目,

2015-05-18 15:57:58 2313 2

原创 Shell中的进制转换

在Shell中默认表示数值为十进制,那么二进制、八进制和十六进制如何表示呢?    方法1:使用前缀。    0开头表示八进制,0x开头表示十六进制。    如下:#-----------------------------/chapter4/ex4-35.sh------------------#! /bin/sh#十进制20((x=20))echo "$x"

2015-05-18 15:51:53 2664

原创 Shell中的运算符

Shell中也可以实现基本算术运算,以及位运算。    我们总结起来有如下几点:    1)基本的算术运算符:+、-、*、/、**都支持,最后的**是幂运算;    2)算术运算要和一些命令结合才能使用,如expr`...`命令,$((...))命令,$[...]命令,let命令,注意:expr后面是反引号;    3)一定要注意所有运算符两边都要有空格,比如result=`exp

2015-05-18 14:52:53 1406

原创 Shell中的条件判断语句if~then~fi

Shell中的条件判断语句是前面一篇“Shell中的条件测试语句”的升级篇,也就是说,前面的测试语句是为了现在的判断语句if~then~fi语句服务的。    我们还是按照注意点和代码实现的方式铺开:        1)基本的if-then-fi语句可以用来判断基本的单层的分支结构,其形式如下:其中if后面的测试语句一般都使用[]命令来做。如下面的例子:#---------

2015-05-18 08:59:51 48610

原创 Shell中的条件测试语句

Shell有条件测试语句,一般用test命令或是[]命令来完成,它们是条件判断语句if~then语句的基础,特别是[]命令。下面我们讲解一些条件测试语句。1. test命令实现条件测试    对于检测系统中某些文件是否存在,或者相关属性时,test命令很好用。    其基本语法如下:    test命令还可以测试字符串:    test命令还可以

2015-05-17 21:56:22 1593

原创 Shell中的变量

这篇博文我们首先简单介绍Shell中变量的几个注意点,然后通过实际的例子来学习。    关于Shell的变量,总结起来有如下几个注意点:    1)Shell中的变量是不区分类型的,这点和C++、java语言不同。变量统一地按照字符串存储;    2)允许使用declare来改变变量的类型为整型,如declare -i x   这样并不改变x本身的值    3)echo语句中显示变

2015-05-17 15:22:44 1194

原创 Divide Two Integers ——解题报告

【题目】Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.    【分析】    基本思想:任何数都可以分成二进制的幂的线性表示。    例子:以87除4举例, (4 * 2 = 8) => (

2015-05-15 13:23:12 644

原创 Remove Element ——结题报告

【题目】Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter what you leave beyond the new le

2015-05-12 13:39:43 743

原创 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 in

2015-05-12 10:31:09 708

原创 Reverse Nodes in k-Group——解题报告

【题目】Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of k then left-out nodes in the end should remai

2015-05-12 09:38:00 801

原创 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 constan

2015-05-12 08:12:38 762

原创 范式和反范式的优缺点

在设计数据库时,有范式和反范式的讲究,下面总结一下。    范式的优点:    1)范式化的数据库更新起来更加快;    2)范式化之后,只有很少的重复数据,只需要修改更少的数据;    3)范式化的表更小,可以在内存中执行;    4)很少的冗余数据,在查询的时候需要更少的distinct或者group by语句。    范式的缺点:    5)范式化的表

2015-05-11 22:28:18 8898

原创 详解char和varchar的区别

MySQL中的字符串有两个常用的类型:char和varchar,二者各有优势,下面我们来详细分析一下。1、char(n)类型    char类型时定长的类型,即当定义的是char(10),输入的是"abc"这三个字符时,它们占的空间一样是10个字节,包括7个空字节。当输入的字符长度超过指定的数时,char会截取超出的字符。而且,当存储char值时,MySQL是自动删除输入字符串末尾

2015-05-11 21:05:59 15591 1

原创 MySQL中整各种int类型的范围和存储大小

MySQL中中的整数类型int主要有如下几种:    tinyint 的范围是-128~127;    int的范围是-2^31 (-2,147,483,648) 到 2^31 – 1 (2,147,483,647) 的整型数据(所有数字),存储大小为4个字节;    bigint的范围是 -2^63 (-9223372036854775808) 到 2^63-1 (92233

2015-05-11 20:09:40 10366 2

原创 数据库设计中关于数据类型的优化

在数据库设计中,尤其在建表的时候,我们需要分别对每个字段确定对应的数据类型。那么MySQL支持的数据类型非常多,选择正确的、合理的数据类型对后面的查找速度有直接的影响。不管存储哪种类型的数据,下面有几个简单的设计原则:1、尽量使用可以正确存储数据的最小数据类型    更小的数据类型通常更快,因为它们占用更少的磁盘、内存和CPU,并且在处理时需要的CPU周期也更少。不过需要确保在设计

2015-05-11 19:56:03 787

原创 Merge k Sorted Lists ——待解决TLE

【题目】Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.    【分析】    思路基于两个有序链表合并。只不过每次都需要遍历选出K个链表中最小的那个数。    【代码】    下面的代码始终LTE,原因是一个很

2015-05-09 11:16:31 474

原创 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:"((()))", "(()())", "(())()", "()((

2015-05-09 09:07:59 825

原创 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.    【分析】    不要忘记先判断两个链表是否有空链表。其余的使用递归和非递归

2015-05-08 13:01:33 1012

原创 Valid Parentheses——解题报告

【题目】    Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are

2015-05-08 10:22:37 646

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

2015-05-08 09:47:32 662

原创 Letter Combinations of a Phone Number——解题报告 (回溯法的应用 )

【题目】      Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.

2015-05-08 08:33:59 2387

原创 Linux中的head, tail,wc命令

Linux系统中读取文件还有几个命令:head, tail, wc。我们解释一下这几个命令。1. head:显示前面几行head file:显示1-10行(默认为10行)head -n 20 file:显示1-20行head -n -20 file:显示1-120行,-20表示不显示后20行2. tail:显示后面几行tail与head类似,只说明“+”

2015-05-07 22:36:14 3372

原创 kSum问题的总结

kSum问题是一类题型,常见的有2Sum,3Sum,4Sum等。这篇博文就来总结一些kSum问题的解法,以及对应的时间复杂度。    1. 2Sum    在一个给定的数组nums中,寻找和为定值target的两个数。    【解法1】:把数组排序,然后使用two pointers的方法来求解。时间复杂度分析:排序O(nlogn),两指针遍历O(n),总体O(nlogn).

2015-05-07 11:11:07 2441

原创 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 ha

2015-05-07 10:36:15 728

原创 3Sum——解题报告

【题目】     Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:Elements in a triplet (

2015-05-07 10:01:46 827

原创 Longest Common Prefix ——解题报告

【题目】    Write a function to find the longest common prefix string amongst an array of strings.    【分析】     公共前缀指的是所有字符串的前缀都相同。显然,这个最长公共前缀的长度不会超过所有字符串中最短的那个。    我们先求得最短串长minLen,然后遍历所有字符串中的前

2015-05-07 08:08:42 1090

原创 Roman to Integer ——解题报告

【题目】    Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.    【分析】    这个和上篇博文中把数字转换为罗马数字正好相反,逻辑过程有点儿复杂。    其实解法来源于对罗马数字(字符串)的观察,

2015-05-06 20:17:46 590

原创 Integer to Roman ——解题报告

【题目】    Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.    分析:    首先,我们需要知道罗马数字的表示方法,可参考链接:http://blog.csdn.net/ljiabin/article

2015-05-06 19:30:16 598

原创 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). Fin

2015-05-06 17:48:26 554

原创 Palindrome Number ——解题笔记

【题目】 Determine whether an integer is a palindrome. Do this without extra space.click to show spoilers.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of co

2015-05-06 10:47:16 907

空空如也

空空如也

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

TA关注的人

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