- 博客(33)
- 收藏
- 关注
![](https://csdnimg.cn/release/blogv2/dist/pc/img/listFixedTop.png)
原创 leetcode algorithm java
binary tree# 编号题目标签解答117给每一层节点添加next指针 IIBinary Tree/BFS2种
2018-12-06 18:34:00
84
原创 Spark scala api(二)键值对操作
创建Pair RDD很多存储键值对的数据格式会在读取时直接返回由其键值对数据组成的pair RDD当需要把一个普通RDD转化而pair RDD时,可以使用map函数//使用第一个单词作为键创建pair RDDval pairs = lines.map(x => (x.split(" "))(0), x)Pair RDD的转化操作Pair RDD也还是RDD,同样支持RDD所支持...
2019-03-06 11:14:36
297
转载 leetcode-44 wildcard matching
Given an input string (s) and a pattern §, implement wildcard pattern matching with support for ‘?’ and ‘*’.‘?’ Matches any single character.‘*’ Matches any sequence of characters (including the emp...
2019-03-05 09:58:03
129
原创 Spark scala api(一)RDD编程
基础初始化sparkval conf = new SparkConf().setAppName("wordcount")val sc = new SparkContext(conf)转化操作和行动操作的区别在于spark计算rdd的方式不同,只有在第一次在一个行动操作中用到转化操作中的rdd时,才会真正计算这些rdd。创建rdd// 驱动器程序对一个集合进行并行化val lines...
2019-03-04 14:15:26
452
转载 scala 组合和继承(一)- 8
概述定义一个新类主要有两种模式:一个通过组合的方式,新创建的类通过引用其他类的组合而成,一个是通过组合的方式假设需要定义一个函数库。这个库用来定义在平面上(二维空间)的布局元素,每个元素使用一个含有文字的矩形来表示。首先定义一个类构造工厂方法elem,根据传入的参数来创建一个布局元素。elem(s: String):Element布局元素使用类型Element来构造其模型组合和继承...
2019-01-22 11:14:04
296
转载 scala函数(二)-7
尾递归前面可以使用递归函数消除需要使用var变量的while函数下面为一个使用逼近方法的一个递归函数表达式def approximate(guess: Double) : Double =if (isGoodEnough(guess)) guesselse approximate(improve(guess))通过实现合适的 isGoodEnough 和 improve 函数,说明这段...
2019-01-21 14:25:30
106
转载 scala 函数(一) - 6
类成员函数常见的定义函数的方法:import scala.io.Sourceobject LongLines{ def processFile(filename:String, width: Int) { val source = Source.fromFile(filename) for(line <- source.getLines()) processLine(f...
2019-01-21 09:31:35
466
转载 scala 控制语句 -5
ifvar age=25val result = if(age>20) “worker” else “student”println(result)这段代码比java代码简短,并且result无需使用var变量,使用val为函数式编程风格while循环//求两个数的最大公约数def gcdLoop(x:Long, y:Long) :Long = {var a=xvar ...
2019-01-18 16:02:26
128
转载 scala 类和对象(二)- 4
实践操作定义Rational类Rational类的定义规范有理数rational定义:一个有理数rational可以表示为分数形式 n/d,其中n是分子(numerator),d是分母(denominator)定义Rationalclass Rational(n:Int, d:Int)scala类的定义可以有参数,scala编译器会将不属于类成员和类方法的其它代码用作类的主构造函数创...
2019-01-18 15:00:04
219
转载 scala基本数据类型及其操作-3
基本数据类型简介Scala数据类型都是对象(比如整数)基本数据类型:整数类型:Byte,Short,Int,Long,Char数值类型:整数类型+Float,DoubleString除了string定义在java.lang包中,其他的数组类型都定义在scala包中scala> var hex=0x5hex: Int = 5scala> var hex2=0x00ff...
2019-01-18 10:00:25
204
转载 scala-类和对象-2
类和对象的定义class ChechsumAccumulator{private var sum=0def add(b:Byte):Unit = sum += bdef checkSum() :Int = ~(sum & 0xFF) +1}Scala 类的缺省修饰符为publicScala方法的参数都是val类型,不能修改参数的值对于不含返回值的方法,可以hulve掉=...
2019-01-18 09:29:00
183
转载 起步scala-1
使用 Scala 解释器,首先你需要下载安装 Scala 运行环境。 然后在命令行输入scala,则进入 scala 解释器可以使用 :help 命令列出一些常用的 Scala 解释器命令。定义变量Scala 定义了两种类型的变量 val 和 var ,val 类似于Java中的 final 变量,一旦初始化之后,不可以重新赋值(我们可以称它为 常变量 )。而 var 类似于一般的非 fin...
2019-01-17 18:09:42
122
原创 18 4sum
my solution:class Solution { public List<List<Integer>> fourSum(int[] nums, int target) { Arrays.sort(nums); // for(int i = 0; i < nums.length;i++) // { ...
2019-01-10 21:33:10
95
转载 linux 安装mysql
https://blog.csdn.net/qq_37936542/article/details/79499989安装rpm包软件,如mysql%%查看系统中安装的rpm包rpm -qa | grep mysql%%上传rpm安装包 https://blog.csdn.net/qq_37936542/article/details/79498905MySQL-client-5....
2019-01-09 19:20:27
81
转载 linux的命令操作
1、日常操作命令**查看当前所在的工作目录pwd**查看当前系统的时间date**查看有谁在线(哪些人登陆到了服务器)who 查看当前在线last 查看最近的登陆历史记录2、文件系统操作**ls / 查看根目录下的子节点(文件夹和文件)信息ls -al -a是显示隐藏文件 -l是以更详细的列表形式显示**切换目录cd /home**创建文件夹mkdir...
2019-01-09 16:36:37
79
转载 虚拟机联网安装问题
minimal最小化安装eth0默认没有自启用修改配置文件onboot=true修改静态地址后发现无法ping外网需要设置网关route add default gw 192.168.33.1添加nameservervi /etc/resolv.confnameserver 192.168.33.1解决克隆后eth0不见的问题直接修改 /etc/sysconfig/netw...
2019-01-09 16:24:15
88
原创 155. Min Stack
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) – Push element x onto stack.pop() – Removes the element on top of the stack.top() – Get the ...
2019-01-06 17:44:49
84
原创 141. Linked List Cycle
Given a linked list, determine if it has a cycle in it.设定两个指针,p2每次走两步,p1每次走一步,最后如果fast遇到空指针则代表图中没有环。由于每个链表的节点只能指向一个节点,如果遇到null则代表肯定不会遇到环。相反,如果链表中遇到了环,如下面左图所示,利用相对位置的观点,假设p1是静止的,那么p2每次移动都是在向p1走近一步,最终...
2018-12-28 11:15:48
122
1
原创 234. Palindrome Linked List
Given a singly linked list, determine if it is a palindrome.Example 1:Input: 1->2Output: falseExample 2:Input: 1->2->2->1Output: trueFollow up:Could you do it in O(n) time and O(1)...
2018-12-28 10:11:43
80
原创 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. ...
2018-12-27 18:10:01
65
原创 16. 3 sum closet
Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each input would ...
2018-12-27 10:28:17
105
原创 15. 3 sum
Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:The solution set must not contai...
2018-12-27 10:14:40
107
原创 windows hadoop ecipse 配置
首先安装 ant,配置 ant 环境变量安装 eclipse 和 hadoop2.9.1 参考网址下载eclipse_hadoop插件网址按照该博客或者下载网址下面的说明创建hadoop插件**中间会遇到一些问题,需要去调整一些东西 **https://zhuanlan.zhihu.com/p/38500829创建成功后,可以得到然后将插件放入eclipse的plugins文件夹下...
2018-12-20 18:47:20
76
原创 189 Rotate Array
将数组循环顺移k个位置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,2,3,4,5,6]rotate 2 steps to the right: [6,7,1,2,3,4,5]rotate 3 steps to...
2018-12-20 10:01:54
113
原创 394. Decode String
给定一个编码字符串,返回它的解码字符串。编码规则是:k[encoded_string],其中方括号内的encoded_string重复k次,k是正整数。您可以假设输入字符串始终有效; 没有多余的空白区域,方括号格式正确等。此外,您可以假设原始数据不包含任何数字,并且该数字仅用于那些重复数字k。例如,不会有像3a或那样的输入2[4]。例子:s =“3 [a] 2 [bc]”,返回“aaab...
2018-12-19 20:06:18
251
原创 hadoop version3 第二章 关于MapReduce
java mapreduce寻找每一年全球的最高气温输入值的key是文件中的行偏移量,map函数不需要该信息,所以将其忽略。value是一行文本信息map的功能是从中找出每年的温度,统计到一个对应的数组中。reduce的功能是遍历每年的列表,并从其中找到最高温度。Mapper类import java.io.IOException;import org.apache.hadoo...
2018-12-19 09:20:34
72
原创 207. Course Schedule
判断有向图中有没有环There are a total of n courses you have to take, labeled from 0 to n-1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed...
2018-12-17 17:05:37
61
原创 101. Symmetric Tree
问题链接判断二叉树是否为对称二叉树Iteration——BFS/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; }...
2018-12-14 10:07:13
58
原创 98. Validate Binary Search Tree
问题链接判断是否有效搜索二叉树深度优先搜索递归解决方案class Solution { public boolean isValidBST(TreeNode root) { if(root == null) return true; return helper(root, null,null); } //low 表示 当前节点应该满足...
2018-12-13 21:51:30
73
原创 337. House Robber II
小偷又发现了自己盗窃的新地方。 这个区域只有一个入口,称为“根”。 除了根之外,每个房子都有一个且只有一个父母的房子。 巡逻后,聪明的小偷意识到“这个地方的所有房屋都形成了一棵二叉树”。 如果两个直接连接的房屋在同一天晚上被闯入,它将自动联系警方。确定小偷今晚可以抢劫的最大金额,而不会提醒警方。** 题目连接**正确答案采用dfsclass Solution { public i...
2018-12-12 10:23:33
94
原创 199. Binary Tree Right Side View
问题链接问题描述站在二叉树的右侧所看到的从上到下的节点/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * ...
2018-12-07 09:29:58
58
原创 129. Sum Root to Leaf Numbers
[问题链接](https://leetcode.com/problems/sum-root-to-leaf-numbers/)Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf pat...
2018-12-06 18:49:46
68
原创 leetcode 117 Populating Next Right Pointers in Each Node II
leetcode 117 Populating Next Right Pointers in Each Node II 广度优先遍历问题地址Given a binary treestruct TreeLinkNode {TreeLinkNode *left;TreeLinkNode *right;TreeLinkNode *next;}Populate each next poin...
2018-12-06 08:46:08
110
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人