This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
int largestRectangleArea(vector<int>& height) { | |
height.insert(height.begin(),0); // dummy "0" added to make sure stack s will never be empty | |
height.push_back(0); // dummy "0" added to clear the stack at the end | |
int len = height.size(); | |
int i, res = 0, idx; | |
stack<int> s; // stack to save "height" index | |
s.push(0); // index to the first dummy "0" | |
for(i=1;i<len;i++) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def largestRectangleArea(self, height): | |
height.append(0) | |
stack = [-1] | |
ans = 0 | |
for i in xrange(len(height)): | |
while height[i] < height[stack[-1]]: | |
h = height[stack.pop()] | |
w = i - stack[-1] - 1 | |
ans = max(ans, h * w) | |
stack.append(i) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution { | |
public int largestRectangleArea(int[] height) { | |
int len = height.length; | |
Stack<Integer> s = new Stack<Integer>(); | |
int maxArea = 0; | |
for(int i = 0; i <= len; i++){ | |
int h = (i == len ? 0 : height[i]); | |
if(s.isEmpty() || h >= height[s.peek()]){ | |
s.push(i); | |
}else{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static int largestRectangleArea(int[] height) { | |
if (height == null || height.length == 0) { | |
return 0; | |
} | |
int[] lessFromLeft = new int[height.length]; // idx of the first bar the left that is lower than current | |
int[] lessFromRight = new int[height.length]; // idx of the first bar the right that is lower than current | |
lessFromRight[height.length - 1] = height.length; | |
lessFromLeft[0] = -1; | |
for (int i = 1; i < height.length; i++) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
int maxCombineArea(const vector<int> &height, int s, int m, int e) { | |
// Expand from the middle to find the max area containing height[m] and height[m+1] | |
int i = m, j = m+1; | |
int area = 0, h = min(height[i], height[j]); | |
while(i >= s && j <= e) { | |
h = min(h, min(height[i], height[j])); | |
area = max(area, (j-i+1) * h); | |
if (i == s) { | |
++j; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <algorithm> | |
#include <bits/stdc++.h> | |
#include <stack> | |
using namespace std; | |
// logic is each time character is pushed over stack will be checked with following character if it same continue else print the char | |
void calculate(string str){ | |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import absolute_import, division, print_function, unicode_literals | |
!pip install tf-nightly-gpu-2.0-preview | |
import tensorflow as tf | |
import os | |
import numpy as np | |
import matplotlib.pyplot as plt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_URL = "https://storage.googleapis.com/download.tensorflow.org/example_images/flower_photos.tgz" | |
zip_file = tf.keras.utils.get_file(origin=_URL, | |
fname="flower_photos.tgz", | |
extract=True) | |
base_dir = os.path.join(os.path.dirname(zip_file), 'flower_photos') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IMAGE_SIZE = 224 | |
BATCH_SIZE = 64 | |
datagen = tf.keras.preprocessing.image.ImageDataGenerator( | |
rescale=1./255, | |
validation_split=0.2) | |
train_generator = datagen.flow_from_directory( | |
base_dir, | |
target_size=(IMAGE_SIZE, IMAGE_SIZE), |
OlderNewer