499.Insert Interval-单词计数 (Map Reduce版本)(容易题)
来源:互联网 发布:手机中文解压软件 编辑:程序博客网 时间:2024/06/05 05:51
翻转字符串
题目
使用 map reduce 来计算单词频率
https://hadoop.apache.org/docs/r1.2.1/mapred_tutorial.html#Example%3A+WordCount+v1.0样例
- ###题解###
/** * Definition of OutputCollector: * class OutputCollector<K, V> { * public void collect(K key, V value); * // Adds a key/value pair to the output buffer * } */public class WordCount { //http://www.cnblogs.com/inevermore/p/5232534.html public static class Map { public void map(String key, String value, OutputCollector<String, Integer> output) { String[] arr = value.split(" "); for (int i=0;i<arr.length;i++) { output.collect(arr[i],1); } } } public static class Reduce { public void reduce(String key, Iterator<Integer> values, OutputCollector<String, Integer> output) { int sum = 0; while (values.hasNext()) { sum += values.next().intValue(); } output.collect(key, sum); } }}
Last Update 2016.9.18
0 0
- 499.Insert Interval-单词计数 (Map Reduce版本)(容易题)
- 单词计数 (Map Reduce版本)
- 单词计数(Map Reduce)-lintcode
- Map/Reduce原理(超容易理解版本)
- 30.Insert Interval-插入区间(容易题)
- 使用Hadoop中的map-reduce机制实现单词的计数
- 用insert重写单词计数程序
- 用insert重写单词计数程序
- Hard 57题 Insert Interval
- LeetCode(57) Insert Interval
- LeetCode OJ算法题(五十六):Insert Interval
- Insert Interval
- Insert Interval
- Insert Interval
- Insert Interval
- Insert Interval
- Insert Interval
- Insert Interval
- 497.Shape Factory-形状工厂(容易题)
- 异步加载<笔记>
- PHP编写RESTful接口
- Java中HashMap遍历的两种方式
- Java中关于HashMap的使用和遍历
- 499.Insert Interval-单词计数 (Map Reduce版本)(容易题)
- 动态规划问题系统---climbing-stairs
- 解决Mac上Qt出现Project ERROR: Xcode not set up properly错误方法
- 欢迎使用CSDN-markdown编辑器
- mvn clean install 与 mvn install 的区别(为啥用clean)[转]
- Unity Editor(一)OnInspectorGUI的重写与面板的创建
- 内存分配函数(C语言)
- Leetcode 173. Binary Search Tree Iterator (Medium) (cpp)
- golang语言中map的初始化及使用:代码示例