-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeleteColumnstoMakeSorted.html
More file actions
65 lines (57 loc) · 1.59 KB
/
DeleteColumnstoMakeSorted.html
File metadata and controls
65 lines (57 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LeetCode Day 8</title>
<style>
body {
background: yellowgreen;
}
pre {
color: rgb(17, 0, 255);
font-size: 20px;
}
</style>
</head>
<body>
<h1>You are given an array of n strings strs, all of the same length.
</br>
The strings can be arranged such that there is one on each line, making a grid. For example, strs = ["abc",
</br>
"bce", "cae"] can be arranged as:</h1>
<pre>
Example 1:
Input: strs = ["cba","daf","ghi"]
Output: 1
Explanation: The grid looks as follows:
cba
daf
ghi
Columns 0 and 2 are sorted, but column 1 is not, so you only need to delete 1 column.
Example 3:
Input: strs = ["zyx","wvu","tsr"]
Output: 3
Explanation: The grid looks as follows:
zyx
wvu
tsr
All 3 columns are not sorted, so you will delete all 3.
</pre>
</body>
<script>
strs = ["cba", "daf", "ghi"]
var elements = []
for (let i = 0; i < strs.length; i++) {
for(var j=0;j<strs[i].length;j++){
elements.push(strs[i][j])
}
if(elements[i]!=elements.sort()[i]){
console.log(elements[i],elements.sort()[i]);
}
}
console.log(elements);
// not yet complete
</script>
</html>