ขนาดวิดีโอ: 1280 X 720853 X 480640 X 360
แสดงแผงควบคุมโปรแกรมเล่น
เล่นอัตโนมัติ
เล่นใหม่
class Solution { public: vector left_smaller(vector &arr) { vector ls(arr.size(), 0); stack s; for (unsigned int i = 0; i < arr.size(); i++) { while (!s.empty() and s.top() >= arr[i]) s.pop(); if (!s.empty()) ls[i] = s.top(); else ls[i] = 0; s.push(arr[i]); } //print_arr(ls); return ls; } void print_arr(vector arr) { for (int i = 0; i < arr.size(); i++) cout
Table of Contents0:00 Problem Statement2:27 Solution8:16 Pseudo Code11:12 Code
class Solution {
public:
vector left_smaller(vector &arr) {
vector ls(arr.size(), 0);
stack s;
for (unsigned int i = 0; i < arr.size(); i++) {
while (!s.empty() and s.top() >= arr[i])
s.pop();
if (!s.empty())
ls[i] = s.top();
else
ls[i] = 0;
s.push(arr[i]);
}
//print_arr(ls);
return ls;
}
void print_arr(vector arr) {
for (int i = 0; i < arr.size(); i++)
cout
Table of Contents
0:00 Problem Statement
2:27 Solution
8:16 Pseudo Code
11:12 Code