-
旋转字符串
1.1 旋转字符串题目描述给定一个字符串,要求把字符串前面的若干个字符移动到字符串的尾部,如把字符串“abcdef”前面的2个字符’a’和’b’移动到字符串的尾部,使得原字符串变成字符串“cdefab”。请写一个函数完成此功能,要求对长度为n的字符串操作的时间复杂度为 O(n),空间复杂度为 O(1)。分析与解法解法一:暴力移位法初看此题,可能最先想到的方法是按照题目所要求的,把需要移动的字符一个一个地移动到字符串的尾部,如此我们可以实现一个函数LeftShiftOne(char* s, ...…
-
2018-08-27-文本分类调研
文书分类问题介绍参考网址:http://www.blogjava.net/zhenandaci/archive/2008/05/31/205089.htmlhttps://zhuanlan.zhihu.com/p/259285511. 文本分类方法文本分类问题与其它分类问题没有本质上的区别,其方法可以归结为根据待分类数据的某些特征来进行匹配。因此核心的问题便转化为用哪些特征表示一个文本才能保证有效和快速的分类(注意这两方面的需求往往是互相矛盾的)最早的词匹配法仅仅根据文档中是否出现了与类名...…
-
3. Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters.Examples:Given “abcabcbb”, the answer is “abc”, which the length is 3.Given “bbbbb”, the answer is “b”, with the length of 1.Given “pwwkew”, the answer is “wke”,...…
-
206. Reverse Linked List
Reverse a singly linked list.Example:Input: 1->2->3->4->5->NULLOutput: 5->4->3->2->1->NULLFollow up:A linked list can be reversed either iteratively or recursively. Could you implement both?链接列表可以反复或递归地反转。 你能同时实施吗?思路:...…
-
198. House Robber
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security system connected and it will au...…
-
第8章 数据规整:聚合、合并和重塑
在许多应用中,数据可能分散在许多文件或数据库中,存储的形式也不利于分析。本章关注可以聚合、合并、重塑数据的方法。首先,我会介绍pandas的层次化索引,它广泛用于以上操作。然后,我深入介绍了一些特殊的数据操作。在第14章,你可以看到这些工具的多种应用。8.1 层次化索引层次化索引(hierarchical indexing)是pandas的一项重要功能,它使你能在一个轴上拥有多个(两个以上)索引级别。抽象点说,它使你能以低维度形式处理高维度数据。我们先来看一个简单的例子:创建一个Serie...…
-
160. Intersection of Two Linked Lists
Write a program to find the node at which the intersection of two singly linked lists begins.编写程序以找到两个单链表开头的节点。For example, the following two linked lists:A: a1 → a2 ↘ c1 → c2 → c3 ↗...…
-
第7章 数据清洗和准备
在数据分析和建模的过程中,相当多的时间要用在数据准备上:加载、清理、转换以及重塑。这些工作会占到分析师时间的80%或更多。有时,存储在文件和数据库中的数据的格式不适合某个特定的任务。许多研究者都选择使用通用编程语言(如Python、Perl、R或Java)或UNIX文本处理工具(如sed或awk)对数据格式进行专门处理。幸运的是,pandas和内置的Python标准库提供了一组高级的、灵活的、快速的工具,可以让你轻松地将数据规整为想要的格式。如果你发现了一种本书或pandas库中没有的数据...…
-
204. Count Primes
Count the number of prime numbers less than a non-negative number, n.计算小于非负数n的素数的数量。Example:Input: 10Output: 4Explanation: There are 4 prime numbers less than 10, they are 2, 3, 5, 7.思路: 计算素数的方法 看是否有可以被其整除的数 在1-n之间进行遍历,找出素数 蛮力法,会超时;采用网上思路:厄拉多塞...…
-
2018-08-01-逻辑回归
b站上一个例子: 数据集 2 1 02 2 05 4 14 5 12 3 03 2 06 5 14 1 06 3 17 4 1 step1:加载文件import numpy as npimport matplotlib.pyplot as plt#def loaddatadef loaddata(filename): file = open(filename) x = [] y = [] for line in file.readlines(): ...…
-
第6章 数据加载、存储与文件格式
访问数据是使用本书所介绍的这些工具的第一步。我会着重介绍pandas的数据输入与输出,虽然别的库中也有不少以此为目的的工具。输入输出通常可以划分为几个大类:读取文本文件和其他更高效的磁盘存储格式,加载数据库中的数据,利用Web API操作网络资源。6.1 读写文本格式的数据pandas提供了一些用于将表格型数据读取为DataFrame对象的函数。表6-1对它们进行了总结,其中read_csv和read_table可能会是你今后用得最多的。表6-1 pandas中的解析函数我将大致介绍一下这...…
-
202. Happy Number
Write an algorithm to determine if a number is “happy”.A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the nu...…
-
191. Number of 1 Bits
Write a function that takes an unsigned integer and returns the number of ‘1’ bits it has (also known as the Hamming weight).Example 1:Input: 11Output: 3Explanation: Integer 11 has binary representation 00000000000000000000000000001011Example 2:In...…
-
第5章 pandas入门
虽然pandas采用了大量的NumPy编码风格,但二者最大的不同是pandas是专门为处理表格和混杂数据设计的。而NumPy更适合处理统一的数值数组数据。5.1 pandas的数据结构介绍要使用pandas,你首先就得熟悉它的两个主要数据结构:Series和DataFrame。虽然它们并不能解决所有问题,但它们为大多数应用提供了一种可靠的、易于使用的基础。SeriesSeries是一种类似于一维数组的对象,它由一组数据(各种NumPy数据类型)以及一组与之相关的数据标签(即索引)组成。仅由...…
-
217. Contains Duplicate
Given an array of integers, find if the array contains any duplicates.Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct.Example 1:Input: [1,2,3,1]Output: true...…
-
2018-07-30-多元回归问题
基于numpy库concatenate是一个非常好用的数组操作函数。参考:https://blog.csdn.net/brucewong0516/article/details/79158758Parameters参数 传入的参数必须是一个多个数组的元组或者列表 另外需要指定拼接的方向,默认是 axis = 0,也就是说对0轴的数组对象进行纵向的拼接(纵向的拼接沿着axis= 1方向);注:一般axis = 0,就是对该轴向的数组进行操作,操作方向是另外一个轴,即axis=1。In [...…
-
190. Reverse Bits
Reverse bits of a given 32 bits unsigned integer.Example:Input: 43261596Output: 964176192Explanation: 43261596 represented in binary as 00000010100101000001111010011100, return 964176192 represented in binary as 0011100101111000001010...…
-
842操作系统复习2
OS重点题目整理:1.pv操作PV操作深入理解https://www.zhoulujun.cn/html/theory/os/2015_1024_327.htmlhttp://www.cnblogs.com/liushuijinger/archive/2012/10/16/2725515.html谈到PV操作绕不开一位著名的计算机大神—— Edsgar Wybe Dijkstra,中文名”埃德斯加·狄克斯特拉”,荷兰人,毕业于莱顿大学、剑桥大学。 中国读者常常不明白这一同步机制为什么叫PV...…
-
第3章 Python的数据结构、函数和文件
Python最基础的数据结构开始:元组、列表、字典和集合。创建你自己的、可重复使用的Python函数。学习Python的文件对象,以及如何与本地硬盘交互。3.1 数据结构和序列元组元组是一个固定长度,不可改变的Python序列对象。创建元组的最简单方式,是用逗号分隔一列值:元组中存储的对象可能是可变对象。一旦创建了元组,元组中的对象就不能修改了:In [9]: tup = tuple(['foo', [1, 2], True])In [10]: tup[2] = False--------...…
-
172. Factorial Trailing Zeroes.py
Given an integer n, return the number of trailing zeroes in n!.Example 1:Input: 3Output: 0Explanation:3! = 6, no trailing zero.Example 2:Input: 5Output: 1Explanation: 5! = 120, one trailing zero.Note:Your solution should be in logarithmic time com...…