leecode 解题总结:85. Maximal Rectangle

class Solution {
public:
    int maximalRectangle(vector<vector<char>>& matrix) {
        if(matrix.empty())
		{
			return 0;
		}
		int row = matrix.size();
		int col = matrix.at(0).size();
		vector<int> heights(col , 0);
		int maxArea = INT_MIN;
		int area;
		//计算以当前行及其向上的直方图的高度
		for(int i = 0 ; i < row ; i++)
		{
			for(int j = 0 ; j < col ; j++)
			{
				if('0' == matrix.at(i).at(j))
				{
					heights.at(j) = 0;
				}
				else if('1' == matrix.at(i).at(j))
				{
					heights.at(j)++;
				}
			}
			//计算当前行及其向上部分的直方图的面积
			area = largestRectangleArea(heights);
			maxArea = max(area , maxArea);
		}
		return maxArea;
    }

	//求最大矩形高度,用栈维护一个单调非递减区间的下标;当前元素 >= 栈顶对应高度, 将当前元素下标压入栈;
	//一旦遇到当前元素大于栈顶元素,则计算以栈顶高度为最小值的矩阵的最大面积,面积 = 栈顶对应高度 * (终点 - 起点 + 1)
	//终点=当前元素对应位置 - 1 , 起点=弹出栈顶后的新栈顶位置+1;不断弹出栈顶,直到当前元素 >= 栈顶对应高度
	int largestRectangleArea(vector<int>& heights)
	{
		if(heights.empty())
		{
			return 0;
		}
		int size = heights.size();
		stack<int> hists;
		int i = 0;
		int top;
		int width;
		int area = INT_MIN;
		while(i < size)
		{
			if(hists.empty() || heights.at(i) >= heights.at( hists.top() ))
			{
				hists.push(i++);
			}
			//需要计算最大面积
			else
			{
				top = hists.top();
				hists.pop();
				width = hists.empty() ? i : (i - 1 - hists.top());
				area = max(area , heights.at(top) * width);
			}
		}
		//将最后元素再做一次计算
		while(!hists.empty())
		{
			top = hists.top();
			hists.pop();
			width = hists.empty() ? i : (i - 1 - hists.top());
			area = max(area , heights.at(top) * width);
		}
		return area;
	}
};

root@zhaosai conf]# sqoop import --connect jdbc:mysql://192.168.160.130:3306/mydb --username root -P --table news --hive-import --hive-table mydb.news --incremental append --check-column id --last-value 0 --split-by id --target-dir /hdfs://zhaosai:9000/user/hive/warehouse/news --num-mappers 1 23/06/07 17:23:56 INFO sqoop.Sqoop: Running Sqoop version: 1.4.7 Enter password: 23/06/07 17:24:04 INFO tool.BaseSqoopTool: Using Hive-specific delimiters for output. You can override 23/06/07 17:24:04 INFO tool.BaseSqoopTool: delimiters with --fields-terminated-by, etc. 23/06/07 17:24:04 INFO manager.MySQLManager: Preparing to use a MySQL streaming resultset. 23/06/07 17:24:04 INFO tool.CodeGenTool: Beginning code generation Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary. 23/06/07 17:24:04 INFO manager.SqlManager: Executing SQL statement: SELECT t.* FROM `news` AS t LIMIT 1 23/06/07 17:24:04 INFO manager.SqlManager: Executing SQL statement: SELECT t.* FROM `news` AS t LIMIT 1 23/06/07 17:24:04 INFO orm.CompilationManager: HADOOP_MAPRED_HOME is /opt/programs/hadoop-2.7.6 注: /tmp/sqoop-root/compile/b07035b094b6ac39b87f2ef11261c934/news.java使用或覆盖了已过时的 API。 注: 有关详细信息, 请使用 -Xlint:deprecation 重新编译。 23/06/07 17:24:05 INFO orm.CompilationManager: Writing jar file: /tmp/sqoop-root/compile/b07035b094b6ac39b87f2ef11261c934/news.jar 23/06/07 17:24:05 INFO tool.ImportTool: Maximal id query for free form incremental import: SELECT MAX(`id`) FROM `news` 23/06/07 17:24:05 ERROR tool.ImportTool: Import failed: java.io.IOException: java.sql.SQLSyntaxErrorException: Unknown column 'id' in 'field list' at org.apache.sqoop.tool.ImportTool.initIncrementalConstraints(ImportTool.java:322) at org.apache.sqoop.tool.ImportTool.importTable(ImportTool.java:511) at org.apache.sqoop.tool.ImportTool.run(ImportTool.java:628) at org.apache.sqoop.Sqoop.run(Sqoop.java:147) at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:70) at org.apache.sqoop.Sqoop.runSqoop(Sqoop.java:183) at org.apache.sqoop.Sqoop.runTool(Sqoop.java:234) at org.apache.sqoop.Sqoop.runTool(Sqoop.java:243) at org.apache.sqoop.Sqoop.main(Sqoop.java:252) Caused by: java.sql.SQLSyntaxErrorException: Unknown column 'id' in 'field list' at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) at com.mysql.cj.jdbc.StatementImpl.executeQuery(StatementImpl.java:1200) at org.apache.sqoop.tool.ImportTool.getMaxColumnId(ImportTool.java:238) at org.apache.sqoop.tool.ImportTool.initIncrementalConstraints(ImportTool.java:309)
最新发布
06-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值