首页 文章 精选 留言 我的

精选列表

搜索[leetcode],共441篇文章
优秀的个人博客,低调大师

leetcode算法题解(Java版)-1-二叉树遍历

又开始刷算法题了,正好在学Java,顺便也练练Java。 题目描述 Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between). For example:Given binary tree{3,9,20,#,#,15,7}, 3 / \ 9 20 / \ 15 7 return its zigzag level order traversal as: [ [3], [20,9], [15,7]] confused what"{1,#,2,3}"means? > read more on how binary tree is serialized on OJ. OJ's Binary Tree Serialization: The serialization of a binary tree follows a level order traversal, where '#' signifies a path terminator where no node exists below. Here's an example: 1 / \ 2 3 / 4 \ 5 The above binary tree is serialized as"{1,2,3,#,#,4,#,#,5}". 我的解答: /** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ import java.util.ArrayList; import java.util.LinkedList; import java.util.Collections; import java.util.Queue; public class Solution { public ArrayList<ArrayList<Integer>> zigzagLevelOrder(TreeNode root) { ArrayList<ArrayList<Integer>> ans=new ArrayList<>(); if(root==null){ return ans; } ArrayList<Integer> tem=new ArrayList<>(); TreeNode lastNode=root; TreeNode levelNode=root; Queue<TreeNode> q=new LinkedList<>(); q.add(root); int cnt=0; while(q.size()!=0){ TreeNode poll=q.poll(); tem.add((Integer)poll.val); if(poll.left!=null){ q.offer(poll.left); lastNode=poll.left; } if(poll.right!=null){ q.offer(poll.right); lastNode=poll.right; } if(levelNode==poll){ if(cnt%2!=0){ Collections.reverse(tem); } levelNode=lastNode; ans.add(new ArrayList<>(tem)); tem.clear(); cnt++; } } return ans; } } 遇到的坑&&小结: 把Collections当成了Collection。实际上,Collections是一个包装类,可以当成专门为Collection中的类服务的工具类,不能被实例化;而Collection是根接口 Java引用变量有两个类型:一个是编译时的类型,一个是运行时的类型。编译时由声明该变量时使用的类型决定,运行时由实际赋值给它的对象的类型决定,当编译时的类型和运行时的类型不一样时,就产生了所谓的多态 在多态中,引用类型时接口或父类,而正真的实现类型是实现接口的类的对象或继承父类的子类对象。比如:Queue<TreeNode> q=new LinkedList<>();其中,引用类型是Queue这个接口,实现类型(也就是运行时的类型)是LinkedList这个实现了Queue接口的类 多态性是对象多种表现形式的体现 `ArrayList> res = new ArrayList>();一般都不这么写(我一开始不造),一般都写成ArrayList> res = new ArrayList<>();`因为不写默认跟前面的走,这是泛型规定的

优秀的个人博客,低调大师

LeetCode 3: 无重复字符的最长子串 Longest Substring Without Repeating Characters

题目: 给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度。 Given a string, find the length of the longest substring without repeating characters. 示例 1: 输入: "abcabcbb" 输出: 3 解释: 因为无重复字符的最长子串是 "abc",所以其长度为 3。 示例 2: 输入: "bbbbb" 输出: 1 解释: 因为无重复字符的最长子串是 "b",所以其长度为 1。 示例 3: 输入: "pwwkew" 输出: 3 解释: 因为无重复字符的最长子串是 "wke",所以其长度为 3。 请注意,你的答案必须是 子串 的长度,"pwke" 是一个子序列,不是子串。 解题思路: 暴力求解, 时间复杂度为 O(n^3), 因为要对所有字符遍历, 对子串遍历确认是否有重复字符, pass 滑动窗口, 维护一个索引 [i,j) 的滑动窗口, 对已存在的字符 i' 直接更新滑动窗口 [i',j), 你需要保留每一个字符值及其索引, 即由字符映射索引位置 哈希映射: Key 为字符值, Value 为索引位置 字符映射: ASCII 码共 128 个字符, 维护一个长度为 128 的整型数组,数组索引值映射 128 个字符,存储元素值为字符位置 哈希映射: Java: class Solution { public int lengthOfLongestSubstring(String s) { char[] chars = s.toCharArray();//转为字符数组 if (chars.length == 0) return 0; HashMap<Character, Integer> map = new HashMap<>();//建立哈希映射 int size = s.length(), count = 0, i = 0; for (int j = 0; j < size; j++) {//遍历字符 if (map.containsKey(chars[j]))//如果映射中存在该字符 i = Math.max(map.get(chars[j]), i);//更新滑动窗口的左边界 i count = Math.max(count, j - i);//更新 count 为最大值 map.put(chars[j], j + 1);//更新映射中该字符映射的 Value 值为当前位置加一 } return count + 1;//返回最大累加总数, 需要加 1 } } Python: class Solution: def lengthOfLongestSubstring(self, s: str) -> int: if not s: return 0 hash_map = dict() # 建立字典 size = len(s) i, count = 0, 0 for j, c in enumerate(s): # 枚举字符 if c in hash_map: # 如果映射中存在该字符 i = max(i, hash_map[c]) # 更新滑动窗口的左边界 i count = max(count, j-i) # 更新 count 为最大值 hash_map[c] = j+1 # 更新映射中该字符映射的 Value 值为当前位置加一 return count+1 # 返回最大累加总数, 需要加 1 字符映射: Java: class Solution { public int lengthOfLongestSubstring(String s) { char[] chars = s.toCharArray(); if (chars.length == 0) return 0; int[] index = new int[128];//建立长度为 128 位的 ASCII 码字符映射表 int size = s.length(), count = 0, i = 0; for (int j = 0; j < size; j++) {//遍历字符 i = Math.max(index[chars[j]], i);//更新滑动窗口的左边界 i count = Math.max(count, j - i);//更新 count 为最大值 index[chars[j]] = j + 1;//更新映射中该字符所在元素值为当前位置加一 } return count + 1;//返回最大累加总数, 需要加 1 } } Python: class Solution: def lengthOfLongestSubstring(self, s: str) -> int: if not s: return 0 size = len(s) i, count = 0, 0 index = [0]*128 # 建立长度为 128 位的 ASCII 码字符映射表 for j, c in enumerate(s): # 枚举字符 i = max(i, index[ord(c)]) # 更新滑动窗口的左边界 i count = max(count, j-i) # 更新 count 为最大值 index[ord(c)] = j+1 # 更新映射中该字符所在元素值为当前位置加一 return count+1 # 返回最大累加总数, 需要加 1 因为 Python 没有字符概念, 需要 ord() 函数转为 ASCII 数字 欢迎关注微.信.公..众.号: 爱写Bug

优秀的个人博客,低调大师

leetcode算法题解(Java版)-5-简单模拟,字符串处理

一、简单贪心 题目描述 Given n non-negative integers a1 , a2 , ..., an , where each represents a point at coordinate (i, ai ). n vertical lines are drawn such that the two endpoints of line i is at (i, ai ) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water. Note: You may not slant the container. 思路 这题在一分钟内就想了个笨方法,迅速敲完,KO! 因为题目还是很简单,不考虑将装水的容器倾斜,所以只要考虑梯形中最短的边和底边的乘积就行了:正反两遍循环数组,第一遍从0~len,先固定最左边的边,从右往左遍历数组,如果碰到大于等于最左边边长的边,那就判断是否大于当前的最大盛水体积并跟新,然后就停止这次循环,将最左边的边向右移动一格,重复操作;第二遍从len~0,和第一遍一样。 代码 public class Solution { public int maxArea(int[] height) { int len=height.length; if(len==0){ return 0; } int maxW=0; for(int i=0;i<len;i++){ for(int j=len-1;j>i;j--){ if(height[j]>=height[i]){ if(height[i]*(j-i)>maxW){ maxW=height[i]*(j-i); } break; } } } for(int i=len-1;i>0;i--){ for(int j=0;j<i;j++){ if(height[j]>=height[i]){ if(height[i]*(i-j)>maxW){ maxW=height[i]*(i-j); } break; } } } return maxW; } } 思路2 好吧,虚心学习,看了一下其他人的代码。发现一个好方法: 从两边往中间走,每次舍弃较短的边,因为宽度减小,要通过高度的增加来弥补 代码 public class Solution { public int maxArea(int[] height) { int len=height.length; if(len==0){ return 0; } int l=0; int r=len-1; int maxW=0; while(l<r){ maxW=Math.max(maxW,Math.min(height[l],height[r])*(r-l)); if(height[l]<height[r]){ l++; } else{ r--; } } return maxW; } } 二、简单回文数字 题目描述 Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers.Some hints: Could negative integers be palindromes? (ie, -1) If you are thinking of converting the integer to string, note the restriction of using extra space. You could also try reversing an integer. However, if you have solved the problem "Reverse Integer", you know that the reversed integer might overflow. How would you handle such case? There is a more generic way of solving this problem. 思路 题目有个限制,就是不能开辟新的空间。 那就和一般的回文串做法不同了,可以这么来搞:干脆求出它翻转过来的整型,最后比较是否值相等。 想到这个思路,是因为int型的特殊基本数据类型,特别对待,哈哈哈 代码 public class Solution { public boolean isPalindrome(int x) { if(x<0){ return false; } int reverse=0; int x_rel=x; while(x!=0){ reverse=reverse*10+x%10; x/=10; } return reverse==x_rel; } } 三、字符串,模拟 题目描述Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input cases. Notes: It is intended for this problem to be specified vaguely (ie, no given input specs). You are responsible to gather all the input requirements up front. spoilers alert... click to show requirements for atoi.Requirements for atoi: The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character, takes an optional initial plus or minus sign followed by as many numerical digits as possible, and interprets them as a numerical value. The string can contain additional characters after those that form the integral number, which are ignored and have no effect on the behavior of this function. If the first sequence of non-whitespace characters in str is not a valid integral number, or if no such sequence exists because either str is empty or it contains only whitespace characters, no conversion is performed. If no valid conversion could be performed, a zero value is returned. If the correct value is out of the range of representable values, INT_MAX (2147483647) or INT_MIN (-2147483648) is returned. 思路 细节要求比较多,正负号,非法字符,溢出等都要考虑。 代码 public class Solution { public int atoi(String str) { if(str==null||str.length()==0){ return 0; } int pos=0; while(str.charAt(pos)==' '){ pos++; } int flag=1; if(str.charAt(pos)=='-'){ flag=-1; pos++; } if(str.charAt(pos)=='+'){ flag=1; pos++; } int len=str.length(); int res=0; for(int i=pos;i<len;i++){ char c=str.charAt(i); if(c<'0'||c>'9'){ break; } if(res>Integer.MAX_VALUE/10||(res==Integer.MAX_VALUE/10&&c>'7')){ if(flag>0){ return Integer.MAX_VALUE; } else{ return Integer.MIN_VALUE; } } res=res*10+(c-'0'); } return res*flag; } }

优秀的个人博客,低调大师

leetcode算法题解(Java版)-4-动态规划(杨辉三角问题)

一、简单模拟 题目描述 Say you have an array for which the i th element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one and sell one share of the stock multiple times). However, you may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again). 思路 肯定是低价买,高价卖出。但是有个限制就是在买进的时候,必须卖出手上的股票。 最低价买,最高价的时候卖。在递增数列中,末项减首项=每项与后一项之差的和。这里不需要考虑交易次数最小,所以可以这么写: 代码 public class Solution { public int maxProfit(int[] prices) { int len=prices.length; int maxPro=0; for(int i=1;i<len;i++){ if(prices[i]>prices[i-1]){ maxPro+=prices[i]-prices[i-1]; } } return maxPro; } } 二、模拟的升级版 题目描述 Say you have an array for which the i th element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), design an algorithm to find the maximum profit. 思路 这题跟上一题不一样的地方在于,是能买卖一次了。 可以先固定局部最小值,后面不断维护跟新局部最大值和局部最小值的差,直到最后找到结果。 做了两道这种最大值和最小值差的问题,总结一下,因为最大值最小值都是在数组中变化的,所以可以考虑先固定出局部的最小值。 代码 import java.lang.Math; public class Solution { public int maxProfit(int[] prices) { int len=prices.length; if(prices==null||len==0){ return 0; } int min=prices[0]; int maxPro=0; for(int i=1;i<len;i++){ if(prices[i]<min){ min=prices[i]; } else{ maxPro=Math.max(prices[i]-min,maxPro); } } return maxPro; } } 三、动态规划 题目描述Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below. For example, given the following triangle [ [2], [3,4], [6,5,7], [4,1,8,3] ] The minimum path sum from top to bottom is11(i.e., 2 + 3 + 5 + 1 = 11). Note: Bonus point if you are able to do this using only O(n) extra space, where n is the total number of rows in the triangle. 思路 经典的三角数组,动态规划问题 详细的请看代码。这里没有开辟新的存储,只是在最后一行上跟新维护每一行的最优解,最后最后一行的第一个数即为所求。 语法点:import java.util.ArrayList;ArrayList.get(index);ArrayList.set(index,value);import java.lang.Math;Math.min(value1,value2); 代码 import java.lang.Math; import java.util.ArrayList; public class Solution { public int minimumTotal(ArrayList<ArrayList<Integer>> triangle) { int len=triangle.size(); if(len==0){ return 0; } if(len==1){ int min=triangle.get(0).get(0); for(int i=0;i<triangle.get(0).size();i++){ if(min>triangle.get(0).get(i)){ min=triangle.get(0).get(i); } } return min; } for(int i=len-2;i>=0;i--){ for(int j=0;j<i+1;j++){ int min=Math.min(triangle.get(len-1).get(j),triangle.get(len-1).get(j+1)); triangle.get(len-1).set(j,triangle.get(i).get(j)+min); } } return (int)triangle.get(len-1).get(0); } } 四、动态规划(杨辉三角) 题目描述 Given an index k, return the k th row of the Pascal's triangle. For example, given k = 3,Return[1,3,3,1]. Note: Could you optimize your algorithm to use only O(k) extra space? 思路 又是个动态规划问题,一开始想复杂了,或者说是没有按计算机思维来思考:我在算C{n_m},就是在算组合数,想通过组合数来打印出数组。 其实是个动态规划,当前行的值是依赖于上一行的。题目要求用O(n)空间来求解,那就设置了一个动态数组,每次从后往前刷新这个数组,即为所求。 代码 import java.util.ArrayList; public class Solution { public ArrayList<Integer> getRow(int rowIndex) { ArrayList<Integer> res=new ArrayList<>(); res.add(1); for(int i=0;i<rowIndex;i++){ for(int j=i;j>0;j--){//注意要从后往前刷新,因为用的是一个动态数组,防止仍有用的数据被新值覆盖 res.set(j,res.get(j)+res.get(j- 1)); } res.add(1); } return res; } }

优秀的个人博客,低调大师

LeetCode 94:二叉树的中序遍历 Binary Tree Inorder Traversal

题目: 给定一个二叉树,返回它的中序 遍历。 Given a binary tree, return the inorder traversal of its nodes' values. 示例: 输入: [1,null,2,3] 1 \ 2 / 3 输出: [1,3,2] 进阶: 递归算法很简单,你可以通过迭代算法完成吗? Follow up: Recursive solution is trivial, could you do it iteratively? 解题思路: 百度百科:二叉树的中序遍历:https://baike.baidu.com/item/中序遍历 遍历顺序:左子节点 --> 根节点 --> 右子节点 如下所示的二叉树: A / \ B C / \ / \ D E F G 其遍历顺序为:D -> B -> E -> A ->F -> C -> G 二叉树遍历可以用 DFS(深度优先搜索)完成,其实现方式为:递归或借助数据结构 栈 迭代。 这种遍历方式本质上是一个先进后出的栈式遍历方式,递归方法实际也是用递归方式实现栈的先进后出。 DFS-递归: Java: class Solution { public List<Integer> inorderTraversal(TreeNode root) { List<Integer> list = new ArrayList<>();//数组 dfs_recursion(root, list);//传入递归函数 return list; } private void dfs_recursion(TreeNode node, List<Integer> list) { if (node == null) return;//基线条件 dfs_recursion(node.left, list);//先遍历左子节点 list.add(node.val);//遍历到左子节点的顶点,取出该节点的值 dfs_recursion(node.right, list);//递归遍历右节点 } } Python3: class Solution: def inorderTraversal(self, root: TreeNode) -> List[int]: #数组 res = list() #传入递归函数 self.dfs_recursion(root, res) return res def dfs_recursion(self, node: TreeNode, res: List[int]): #基线条件 if not node: return #递归遍历左子节点 self.dfs_recursion(node.left, res) #取顶点节点的值 res.append(node.val) #递归遍历右子节点 self.dfs_recursion(node.right, res) DFS-迭代: Java: class Solution { public List<Integer> inorderTraversal(TreeNode root) { List<Integer> list = new ArrayList<>();//数组 if (root == null) return list; Stack<TreeNode> stack = new Stack<>();//用数据结构栈暂存节点 TreeNode cur = root;//定义当前节点 while (!stack.isEmpty() || cur != null) {//循环条件:栈不空或当前节点不空 if (cur != null) {//当前节点不空时 stack.push(cur);//当前节点入栈 cur = cur.left;//刷新当前节点 } else {//当前节点空时 cur = stack.pop();//当前节点的父节点出栈 list.add(cur.val);//数组存入节点的值 cur = cur.right;刷新当前节点 } } return list; } } Python: class Solution: def inorderTraversal(self, root: TreeNode) -> List[int]: #初始化数组、栈 res, stack = list(), list() #当前节点指向根节点 cur = root #递归条件为:栈或当前节点非空 while stack or cur: if cur: #当前节点非空时入栈 stack.append(cur) #刷新当前节点 cur = cur.left else: #当前节点为空时其父节点出栈 cur = stack.pop() #其值存入数组 res.append(cur.val) #刷新当前节点 cur =cur.right return res 一起学习吖,欢迎关注:爱写Bug

优秀的个人博客,低调大师

​LeetCode 26:删除排序数组中的重复项 Remove Duplicates from Sorted Array

给定一个排序数组,你需要在原地删除重复出现的元素,使得每个元素只出现一次,返回移除后数组的新长度。 不要使用额外的数组空间,你必须在原地修改输入数组并在使用 O(1) 额外空间的条件下完成。 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 the input array in-place with O(1) extra memory. 示例 1: 给定数组 nums = [1,1,2], 函数应该返回新的长度 2, 并且原数组 nums 的前两个元素被修改为 1, 2。 你不需要考虑数组中超出新长度后面的元素。 示例 2: 给定 nums = [0,0,1,1,1,2,2,3,3,4], 函数应该返回新的长度 5, 并且原数组 nums 的前五个元素被修改为 0, 1, 2, 3, 4。 你不需要考虑数组中超出新长度后面的元素。 说明: 为什么返回数值是整数,但输出的答案是数组呢? 请注意,输入数组是以“引用”方式传递的,这意味着在函数里修改输入数组对于调用者是可见的。 你可以想象内部操作如下: // nums 是以“引用”方式传递的。也就是说,不对实参做任何拷贝 int len = removeDuplicates(nums); // 在函数里修改输入数组对于调用者是可见的。 // 根据你的函数返回的长度, 它会打印出数组中该长度范围内的所有元素。 for (int i = 0; i < len; i++) { print(nums[i]); } 解题思路: ​ 定义两个指针,指针 i 索引遍历数组,指针 j 索引值与 i 索引值比较,如果相等则 i 继续遍历,如果不等则将索引 i 的值赋值得到索引 j+1 的值。 Java: class Solution { public int removeDuplicates(int[] nums) { int numsLen = nums.length; if (numsLen < 1) return numsLen;//如果数组只有一个值或空数组,直接返回该数组的长度 int j = 0; for (int i = 1; i < numsLen; i++) {//指针 i 从从索引 1 开始遍历数组 if (nums[i] != nums[j]) {//与索引 j 的值比较 nums[++j] = nums[i];//如果不相等 索引j+1 ,并得到索引i的值 } } return j + 1;//返回到指针 j,数组的长度 } } ​ python这道题并没有很特殊的解法。 Python3: class Solution: def removeDuplicates(self, nums: List[int]) -> int: numsLen = len(nums) if(numsLen < 1): return numsLen j = 0 for i in range(1, numsLen): if nums[j] != nums[i]: j += 1 nums[j] = nums[i] return j+1 公众号:爱写bug(ID:iCodeBugs)

优秀的个人博客,低调大师

leetcode 12 ,13 Integer to Roman &amp;&amp;Roman to Integer 罗马与阿拉伯数组转换

12 Integer to Roman 13 Roman to Integer 有可能不注意的结果: class Solution { public: /* 1、相同的数字连写,所表示的数等于这些数字相加得到的数,如:Ⅲ = 3; 2、小的数字在大的数字的右边,所表示的数等于这些数字相加得到的数, 如:Ⅷ = 8;Ⅻ = 12; 3、小的数字,(限于Ⅰ、X 和C)在大的数字的左边,所表示的数等于大数减小数得到的数,如:Ⅳ= 4;Ⅸ= 9; 4、正常使用时,连写的数字重复不得超过三次。(表盘上的四点钟“IIII”例外) 5、在一个数的上面画一条横线,表示这个数扩大1000倍。 */ int romanToInt(string s) { int res=0; int lastValue=0; int digit; for(int i=s.size()-1;i>=0;i--){ switch(s[i]){ case 'I': digit=1; break; case 'V': digit=5; break; case 'X': digit=10; break; case 'L': digit=50; break; case 'C': digit=100; break; case 'D': digit=500; break; case 'M': digit=1000; break; } if(digit>=lastValue){ res+=digit; lastValue=digit; } else res-=digit; } return res; } }; 罗马数字是阿拉伯数字传入之前使用的一种数码。罗马数字采用七个罗马字母作数字、即Ⅰ(1)、X(10)、C(100)、M(1000)、V(5)、L(50)、D(500)。记数的方法: 1. 相同的数字连写,所表示的数等于这些数字相加得到的数,如 Ⅲ=3; 2. 小的数字在大的数字的右边,所表示的数等于这些数字相加得到的数,如 Ⅷ=8、Ⅻ=12; 3. 小的数字(限于 Ⅰ、X 和 C)在大的数字的左边,所表示的数等于大数减小数得到的数,如 Ⅳ=4、Ⅸ=9; 4. 在一个数的上面画一条横线,表示这个数增值 1,000 倍,如 5. string intToRoman(int num) { string table[4][10] = {{"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"}, {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"}, {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"}, {"", "M", "MM", "MMM"} }; string result; int count = 0; while(num > 0){ int temp = num % 10; result = table[count][temp] + result; num /= 10; count++; } return result; } The basic idea is really simple: replace every digit in num by roman numerals. For example, we have a num: 2438. 2 –> “MM” 4 –> “CD” 3 –> “XXX” 8 –> “VIII” Then the result is “MMCDXXXVIII”. M = ["", "M", "MM", "MMM"]; C = ["", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"]; X = ["", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"]; I = ["", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"]; return M[num/1000] + C[(num%1000)/100] + X[(num%100)/10] + I[num%10]; Simple C solution 16ms ● 0 L ljbschen Reputation: 10 void helper (char* ans, int* curp, int step, int one, int five, int ten) { char ch[]={'I','V','X','L','C','D','M'}; int offset=0; if (step==1000) offset=6; else if (step==100) offset=4; else if (step==10) offset=2; else offset=0; if (one==-1) ans[(*curp)++] = ch[offset]; if (ten==1) ans[(*curp)++] = ch[offset+2]; if (five==1) ans[(*curp)++] = ch[offset+1]; while (one-->0) ans[(*curp)++] = ch[offset]; } char* intToRoman(int num) { char *ans = malloc(sizeof(char)*16); int i=0, step=1000, digit=0; int one=0,five=0,ten=0; int curp=0; while (num>0) { digit=num/step; if (digit==9) {one=-1;five=0;ten=1;} else if (digit>=5) {one=digit-5;five=1;ten=0;} else if (digit==4) {one=-1;five=1;ten=0;} else if (digit==0) {one=0;five=0;ten=0;} else {one=digit;five=0;ten=0;} helper(ans,&curp,step,one,five,ten); num-=digit*step; step/=10; } ans[curp]='\0'; return ans; } 《架构大数据—-大数据技术及算法解析》 绪论 2013年被称为大数据元年,据IDC预测,到2020年全球将拥有35ZB(1ZB = 1021字节)的数据,大数据涉及国家战略、区域及企业发展、社会民生的方方面面,掌握大数据的核心概念、模式和技术,就把握了新时代的脉搏。 1.大数据技术概述 1.1大数据的概念 大数据指的是无法在规定时间内用现有的常规软件工具对其内容进行抓取、管理和处理的数据集合。 大数据技术则特指新一代的创新型的技术,能够突破常规软件的限制,是对大数据进行采集、存储和处理的技术的统称。 大数据(BigData)一词正式出现是在2011年麦肯锡全球研究院发布的《大数据:下一个创新、竞争和生产力的前沿》研究报告中。 大数据的4个根本特征: 1.Volume,数据量足够大 2.Variety,数据的种类多样 3.Velocity,数据的增长及处理速度快 4.Value,数据蕴藏价值大 1.2 大数据的行业价值 1.分析用户行为,建立数据模型,并进行预测 WalMart将尿不湿和啤酒摆放在一起的销售策略。 2.提升企业的资产管理,优化企业的业务流程 UPS通过在货车上安装传感器,优化行车路线,2011年,其驾驶员少跑了将近4828万千米的路程。 3.大数据服务智慧城市,智慧交通 智能电表,升级智能电网,由原来的数据库架构升级为HBase,使用Hive进行相关的统计分析。 4.变革公共医疗卫生,对疾病进行预测 Google 的Flurend,百度的疾病预测 5.在金融行业利用大数据进行战略决策和精准营销 6.利用大数据保障公共安全 7.利用大数据促进教育行业变革 8.大数据在改善着每个人的生活 p.s.

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册