- 博客(171)
- 收藏
- 关注
原创 36. Valid Sudoku python
Determine if a9x9 Sudoku boardis valid.Only the filled cells need to be validatedaccording to the following rules:Each rowmust contain thedigits1-9without repetition. Each column must conta...
2019-06-17 22:12:42
306
原创 189. Rotate Array python
Given an array, rotate the array to the right byksteps, wherekis non-negative.Example 1:Input: [1,2,3,4,5,6,7] and k = 3Output: [5,6,7,1,2,3,4]Explanation:rotate 1 steps to the right: [7,1...
2019-06-17 17:39:11
321
原创 KMP与leetcode 28. Implement strStr()
https://www.zhihu.com/question/21923021/answer/281346746知乎的这位老哥解释的不能再清楚了,我就不再重复,就突出一些重点KMP算法的核心,是一个被称为部分匹配表(Partial Match Table)的数组。PMT中的值是字符串的前缀集合与后缀集合(前后缀都不包含本身)的交集中最长元素的长度(或最长公共前后缀)。例如,对于”aba”...
2019-06-10 16:11:04
425
原创 78. Subsets 与90. Subsets II
Given a set ofdistinctintegers,nums, return all possible subsets (the power set).Note:The solution set must not contain duplicate subsets.Example:Input: nums = [1,2,3]Output:[ [3], [1...
2019-06-03 21:22:12
205
原创 88. Merge Sorted Array python
Given two sorted integer arraysnums1andnums2, mergenums2intonums1as one sorted array.Note:The number of elements initialized innums1andnums2aremandnrespectively. You may assume that...
2019-06-01 10:46:11
209
原创 73. Set Matrix Zeroes python
Given amxnmatrix, if an element is 0, set its entire row and column to 0. Do itin-place.Example 1:Input: [ [1,1,1], [1,0,1], [1,1,1]]Output: [ [1,0,1], [0,0,0], [1,0,1]]E...
2019-05-29 20:42:56
222
原创 74. Search a 2D Matrix 240. Search a 2D Matrix II python
Write an efficient algorithm that searches for a value in anmxnmatrix. This matrix has the following properties:Integers in each row are sorted from left to right. The first integer of each row ...
2019-05-29 20:40:15
309
原创 75. Sort Colors python
Given an array withnobjects colored red, white or blue, sort themin-placeso that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the in...
2019-05-29 20:32:28
229
原创 80. Remove Duplicates from Sorted Array II python
Given a sorted arraynums, remove the duplicatesin-placesuch that duplicates appeared at mosttwiceand return the new length.Do not allocate extra space for another array, you must do this bymodi...
2019-05-29 20:16:39
263
原创 56. Merge Intervals python
Given a collection of intervals, merge all overlapping intervals.Example 1:Input: [[1,3],[2,6],[8,10],[15,18]]Output: [[1,6],[8,10],[15,18]]Explanation: Since intervals [1,3] and [2,6] overlaps...
2019-05-26 14:49:48
247
原创 45. Jump Game II python
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Your goal is to...
2019-05-25 17:41:36
209
原创 55. Jump Game python
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine if yo...
2019-05-24 20:59:34
294
原创 54. Spiral Matrix 与59. Spiral Matrix II python
Given a matrix ofmxnelements (mrows,ncolumns), return all elements of the matrix in spiral order.Example 1:Input:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]Output: [1,2,3,6,9,8,7,4,5]...
2019-05-24 20:51:09
136
原创 48. Rotate Image python
You are given annxn2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Note:You have to rotate the imagein-place, which means you have to modify the input 2D matrix d...
2019-05-22 22:14:41
532
原创 133. Clone Graph python
Givena reference of a node in aconnectedundirected graph, return adeep copy(clone) of the graph. Each node in the graph contains a val (int) and a list (List[Node]) of its neighbors.Example:...
2019-05-22 22:11:59
292
原创 130. Surrounded Regions python
Given a 2D board containing'X'and'O'(the letter O), capture all regions surrounded by'X'.A region is captured by flipping all'O's into'X's in that surrounded region.Example:X X X XX O O...
2019-05-21 17:50:09
400
原创 招商银行finetech训练营第三题
第三题是个聚类问题,题目只开放了一个文档,该文档有十个句子,最后得出聚类结果思考:本题没有涉及到很多语义相似,而且有sklearn以及外部文件的限制,所以放弃了词向量,以及bert的使用。1、通过观察数据,发现特征比较明显,大部分可以通过一个核心关键词就可以确定类别。所以第一种方法:(1)、对文本进行分词,大写转小写,去除标点,数字,以及停用词(2)、算出每个词在文章中的tf。(3)、取出...
2019-05-21 14:12:21
624
原创 207. Course Schedule 与210. Course Schedule II
这两个题基本一样,会写一个基本就会写另外一个207.There are a total ofncourses you have to take, labeled from0ton-1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1...
2019-05-20 20:45:47
151
原创 递归总结
分治:将一个难以直接解决的大问题,分割成一些规模较小的相同问题,以便各个击破分而治之。经过反复应用分治手段,可以使子问题与原问题类型一致而规模却不断缩小,最终使子问题缩小到很容易求出其解。由此引出了递归算法:直接或间接调用自身的算法称为递归算法。递归并不是一种必须的算法,而是为了更方便的求得问题的解,所以才引入(例如前序,中序,后序遍历用递归会容易很多,而循环较复杂)。但并非一切递归函数都能用...
2019-05-10 18:18:39
293
原创 167. Two Sum II - Input array is sorted python
Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers ...
2018-09-13 22:09:29
239
原创 160. Intersection of Two Linked Lists python
好久没写总结,今天这个题简单,但是有很多坑,所以记录一下 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 ...
2018-09-12 21:53:47
212
原创 121. Best Time to Buy and Sell Stock python
121. Best Time to Buy and Sell StockSay you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (i.e., buy...
2018-07-25 20:12:36
330
原创 119. Pascal's Triangle II
Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal's triangle.Note that the row index starts from 0.In Pascal's triangle, each number is the sum of the two numbers ...
2018-07-24 21:35:34
195
原创 118. Pascal's Triangle python
Given a non-negative integer numRows, generate the first numRows of Pascal's triangle.In Pascal's triangle, each number is the sum of the two numbers directly above it.Input: 5Output:[ [1...
2018-07-23 21:11:50
394
原创 2 hadoop系列之开发环境安装
一、 windows系统上安装jdk双击jdk-7u80-windows-x64.exe把64位jdk安装到C:\java64目录下,然后把jre安装到C:\java64\jre然后设置java环境变量二、 安装maven解压apache-maven-3.3.3.rar到D:\apache-maven-3.3.3目录下解压maven_jar_dependen...
2018-06-17 10:05:49
187
原创 100. Same Tree python
Given two binary trees, write a function to check if they are the same or not.Two binary trees are considered the same if they are structurally identical and the nodes have the same value.Example 1:In...
2018-06-17 09:48:10
248
原创 Hadoop系列之———前期准备
先安装好Vmware,和CentOS6.5版本,配置好网络(NAT),注意关闭DHCP,需要配置静态的IP等,方便下次开机使用。安装xshell方便使用。 通过xshell连接linux,进行相关设置(蓝色是注释)1. 关闭防火墙,输入:chkconfig iptables off #防火墙开机时不启动,chkconfig是对服务的开机管理service iptables stop...
2018-06-10 16:41:39
185
原创 70. Climbing Stairs python
You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Note: Given n will be a positive int...
2018-05-11 20:43:53
292
原创 Permutations与Permutations II
第一道题是没有重复的情况下,输出一个list的所有排列情况Given a collection of distinct integers, return all possible permutations.Example:Input: [1,2,3]Output:[ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1]...
2018-05-02 19:50:04
536
原创 华为笔试(黑色星期五与编码问题)
第一道题是字符串编码问题,就是输入gbk格式的中文,和字母,截取一定的字符,但是不能把中文截成两半。python默认的是UTF-8的格式,在UTF-8中中文和英文一样处理,都是一个字符的长度,>>>s='中文1234编码5678'>>>s[:1]'中文>>>s[2]'1'>>>s[6:8]'编码'解决方法:先用encode方法...
2018-04-21 22:20:04
440
原创 58. Length of Last Word python
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A word is defined a...
2018-04-20 21:20:17
153
原创 53. Maximum Subarray python
Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.Example:Input: [-2,1,-3,4,-1,2,1,-5,4],Output: 6Explanation: [...
2018-04-19 22:37:56
331
原创 26. Remove Duplicates from Sorted Array python
Given a sorted array nums, 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 modifying...
2018-04-13 21:15:32
125
原创 21. Merge Two Sorted Lists-python
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.Example:Input: 1->2->4, 1->3->4Output: 1->1...
2018-04-11 22:48:21
416
原创 20. 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 all valid but ...
2018-04-10 21:58:20
184
原创 14. Longest Common Prefix
好久没刷leetcode了,上次刷还是大三暑假刷的,当时找工作很心急,并没有静下心来写,匆匆忙忙的刷了四十道,效果并不好。现在研一,希望能够静下心来一天一道,打好基础。之前用的c++写的,c++里面有指针,很方便,也很难,很多人都说面试用c++写是给自己挖了一个坑,我最近用python比较多,所以打算用python刷奉上我的代码class Solution(object): def lon...
2018-04-10 10:46:40
115
原创 kaggle入门笔记(Day5:Inconsistent Data Entry)(数据输入不一致问题)
简单的说就是输入的数据可能本来是一个东西,但是由于字母大小不一致,或者多个空格,或者由于输入问题,或者表达问题, 导致一个单词有相似的表达方法,致统计出来的数据是多个。所以这节课主要是解决这类问题1、Get our environment set up# modules we'll useimport pandas as pdimport numpy as np# helpful mod...
2018-04-08 12:01:30
678
原创 kaggle入门笔记(Day4:Character encodings)
导包# modules we'll useimport pandas as pdimport numpy as np# helpful character encoding moduleimport chardet# set seed for reproducibilitynp.random.seed(0) UTF-8是标准字符编码,所有的python编码都是UTF-8编码,但是你...
2018-04-07 21:56:29
230
原创 kaggle入门笔记(Day3:Parsing Dates)
今天的内容是解析数据,内容比较简单,几句话可以概括。拿到数据之后先判断数据类型(一般都是string类型),然后把string的数据类型转换为相应的形式,比如日期,需要转换为日期的类型,因为如果你想拿到这个日期类型的天,总不能用string类一点点的截取,如果已经转换为datetime类型,可以 使用数据.dt.day来获取到天数。最后通过画图,来查看自己转换的数据是否正确具体步骤1、导入数据# ...
2018-04-06 17:27:27
325
原创 kaggle入门笔记(Day2:Scaling and normalization)
介绍本部分内容之前,先说一下Scaling与normalization的区别一、Scale包括两部分:Standardization(标准化)和Centering(归一化) 1、Standardization: newX = (X- 均值) / 标准差(standard deviation), newX 的均值=0,方差= 1,可用于发现离群点,Python中计算函数为pr...
2018-04-05 21:37:25
1351
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人