- 博客(33)
- 收藏
- 关注
原创 leetcode algorithm java
binary tree # 编号 题目 标签 解答 117 给每一层节点添加next指针 II Binary Tree/BFS 2种
2018-12-06 18:34:00
149
原创 Spark scala api(二)键值对操作
创建Pair RDD 很多存储键值对的数据格式会在读取时直接返回由其键值对数据组成的pair RDD 当需要把一个普通RDD转化而pair RDD时,可以使用map函数 //使用第一个单词作为键创建pair RDD val pairs = lines.map(x => (x.split(" "))(0), x) Pair RDD的转化操作 Pair RDD也还是RDD,同样支持RDD所支持...
2019-03-06 11:14:36
375
转载 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
221
原创 Spark scala api(一)RDD编程
基础 初始化spark val conf = new SparkConf().setAppName("wordcount") val sc = new SparkContext(conf) 转化操作和行动操作的区别在于spark计算rdd的方式不同,只有在第一次在一个行动操作中用到转化操作中的rdd时,才会真正计算这些rdd。 创建rdd // 驱动器程序对一个集合进行并行化 val lines...
2019-03-04 14:15:26
531
转载 scala 组合和继承(一)- 8
概述 定义一个新类主要有两种模式:一个通过组合的方式,新创建的类通过引用其他类的组合而成,一个是通过组合的方式 假设需要定义一个函数库。这个库用来定义在平面上(二维空间)的布局元素,每个元素使用一个含有文字的矩形来表示。 首先定义一个类构造工厂方法elem,根据传入的参数来创建一个布局元素。 elem(s: String):Element 布局元素使用类型Element来构造其模型 组合和继承 ...
2019-01-22 11:14:04
379
转载 scala函数(二)-7
尾递归 前面可以使用递归函数消除需要使用var变量的while函数 下面为一个使用逼近方法的一个递归函数表达式 def approximate(guess: Double) : Double = if (isGoodEnough(guess)) guess else approximate(improve(guess)) 通过实现合适的 isGoodEnough 和 improve 函数,说明这段...
2019-01-21 14:25:30
178
转载 scala 函数(一) - 6
类成员函数 常见的定义函数的方法: import scala.io.Source object LongLines{ def processFile(filename:String, width: Int) { val source = Source.fromFile(filename) for(line <- source.getLines()) processLine(f...
2019-01-21 09:31:35
584
转载 scala 控制语句 -5
if var age=25 val result = if(age>20) “worker” else “student” println(result) 这段代码比java代码简短,并且result无需使用var变量,使用val为函数式编程风格 while循环 //求两个数的最大公约数 def gcdLoop(x:Long, y:Long) :Long = { var a=x var ...
2019-01-18 16:02:26
205
转载 scala 类和对象(二)- 4
实践操作定义Rational类 Rational类的定义规范 有理数rational定义:一个有理数rational可以表示为分数形式 n/d,其中n是分子(numerator),d是分母(denominator) 定义Rational class Rational(n:Int, d:Int) scala类的定义可以有参数,scala编译器会将不属于类成员和类方法的其它代码用作类的主构造函数 创...
2019-01-18 15:00:04
302
转载 scala基本数据类型及其操作-3
基本数据类型简介 Scala数据类型都是对象(比如整数) 基本数据类型: 整数类型:Byte,Short,Int,Long,Char 数值类型:整数类型+Float,Double String 除了string定义在java.lang包中,其他的数组类型都定义在scala包中 scala> var hex=0x5 hex: Int = 5 scala> var hex2=0x00ff...
2019-01-18 10:00:25
270
转载 scala-类和对象-2
类和对象的定义 class ChechsumAccumulator{ private var sum=0 def add(b:Byte):Unit = sum += b def checkSum() :Int = ~(sum & 0xFF) +1 } Scala 类的缺省修饰符为public Scala方法的参数都是val类型,不能修改参数的值 对于不含返回值的方法,可以hulve掉=...
2019-01-18 09:29:00
247
转载 起步scala-1
使用 Scala 解释器,首先你需要下载安装 Scala 运行环境。 然后在命令行输入scala,则进入 scala 解释器 可以使用 :help 命令列出一些常用的 Scala 解释器命令。 定义变量 Scala 定义了两种类型的变量 val 和 var ,val 类似于Java中的 final 变量,一旦初始化之后,不可以重新赋值(我们可以称它为 常变量 )。而 var 类似于一般的非 fin...
2019-01-17 18:09:42
198
原创 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
137
转载 linux 安装mysql
https://blog.youkuaiyun.com/qq_37936542/article/details/79499989 安装rpm包软件,如mysql %%查看系统中安装的rpm包 rpm -qa | grep mysql %%上传rpm安装包 https://blog.youkuaiyun.com/qq_37936542/article/details/79498905 MySQL-client-5....
2019-01-09 19:20:27
123
转载 linux的命令操作
1、日常操作命令 **查看当前所在的工作目录 pwd **查看当前系统的时间 date **查看有谁在线(哪些人登陆到了服务器) who 查看当前在线 last 查看最近的登陆历史记录 2、文件系统操作 ** ls / 查看根目录下的子节点(文件夹和文件)信息 ls -al -a是显示隐藏文件 -l是以更详细的列表形式显示 **切换目录 cd /home **创建文件夹 mkdir...
2019-01-09 16:36:37
115
转载 虚拟机联网安装问题
minimal最小化安装 eth0默认没有自启用 修改配置文件 onboot=true 修改静态地址后发现无法ping外网 需要设置网关 route add default gw 192.168.33.1 添加nameserver vi /etc/resolv.conf nameserver 192.168.33.1 解决克隆后eth0不见的问题 直接修改 /etc/sysconfig/netw...
2019-01-09 16:24:15
151
原创 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
144
原创 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
213
1
原创 234. Palindrome Linked List
Given a singly linked list, determine if it is a palindrome. Example 1: Input: 1->2 Output: false Example 2: Input: 1->2->2->1 Output: true Follow up: Could you do it in O(n) time and O(1)...
2018-12-28 10:11:43
119
原创 206. Reverse Linked List
Reverse a singly linked list. Example: Input: 1->2->3->4->5->NULL Output: 5->4->3->2->1->NULL Follow up: A linked list can be reversed either iteratively or recursively. ...
2018-12-27 18:10:01
106
原创 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
171
原创 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
152
原创 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
110
原创 189 Rotate Array
将数组循环顺移k个位置 Example 1: Input: [1,2,3,4,5,6,7] and k = 3 Output: [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
178
原创 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
316
原创 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
121
原创 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
102
原创 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
86
原创 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
113
原创 337. House Robber II
小偷又发现了自己盗窃的新地方。 这个区域只有一个入口,称为“根”。 除了根之外,每个房子都有一个且只有一个父母的房子。 巡逻后,聪明的小偷意识到“这个地方的所有房屋都形成了一棵二叉树”。 如果两个直接连接的房屋在同一天晚上被闯入,它将自动联系警方。 确定小偷今晚可以抢劫的最大金额,而不会提醒警方。 ** 题目连接** 正确答案 采用dfs class Solution { public i...
2018-12-12 10:23:33
142
原创 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
90
原创 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
105
原创 leetcode 117 Populating Next Right Pointers in Each Node II
leetcode 117 Populating Next Right Pointers in Each Node II 广度优先遍历 问题地址 Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; } Populate each next poin...
2018-12-06 08:46:08
152
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅