Skip to content

Commit

Permalink
add 1324
Browse files Browse the repository at this point in the history
  • Loading branch information
luliyucoordinate committed Jan 19, 2020
1 parent 4ed3557 commit f27854c
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -617,4 +617,5 @@ LeetCode
|1318|[Minimum Flips to Make a OR b Equal to c](https://leetcode.com/problems/minimum-flips-to-make-a-or-b-equal-to-c/)|c|[c++](./src/1318-Minimum-Flips-to-Make-a-OR-b-Equal-to-c/1318.cpp)|[python](./src/1318-Minimum-Flips-to-Make-a-OR-b-Equal-to-c/1318.py)|[go](./src/1318-Minimum-Flips-to-Make-a-OR-b-Equal-to-c/1318.go)|[js](./src/1318-Minimum-Flips-to-Make-a-OR-b-Equal-to-c/1318.js)|[java](./src/1318-Minimum-Flips-to-Make-a-OR-b-Equal-to-c/1318.java)|Medium|
|1319|[Number of Operations to Make Network Connected](https://leetcode.com/problems/number-of-operations-to-make-network-connected/)|c|[c++](./src/1319-Number-of-Operations-to-Make-Network-Connected/1319.cpp)|[python](./src/1319-Number-of-Operations-to-Make-Network-Connected/1319.py)|[go](./src/1319-Number-of-Operations-to-Make-Network-Connected/1319.go)|[js](./src/1319-Number-of-Operations-to-Make-Network-Connected/1319.js)|[java](./src/1319-Number-of-Operations-to-Make-Network-Connected/1319.java)|Medium|
|1320|[Minimum Distance to Type a Word Using Two Fingers](https://leetcode.com/problems/minimum-distance-to-type-a-word-using-two-fingers/)|c|[c++](./src/1320-Minimum-Distance-to-Type-a-Word-Using-Two-Fingers/1320.cpp)|[python](./src/1320-Minimum-Distance-to-Type-a-Word-Using-Two-Fingers/1320.py)|[go](./src/1320-Minimum-Distance-to-Type-a-Word-Using-Two-Fingers/1320.go)|[js](./src/1320-Minimum-Distance-to-Type-a-Word-Using-Two-Fingers/1320.js)|[java](./src/1320-Minimum-Distance-to-Type-a-Word-Using-Two-Fingers/1320.java)|Hard|
|1323|[Maximum 69 Number](https://leetcode.com/problems/maximum-69-number/)|c|[c++](./src/1323-Maximum-69-Number/1323.cpp)|[python](./src/1323-Maximum-69-Number/1323.py)|[go](./src/1323-Maximum-69-Number/1323.go)|[js](./src/1323-Maximum-69-Number/1323.js)|[java](./src/1323-Maximum-69-Number/1323.java)|Easy|
|1323|[Maximum 69 Number](https://leetcode.com/problems/maximum-69-number/)|c|[c++](./src/1323-Maximum-69-Number/1323.cpp)|[python](./src/1323-Maximum-69-Number/1323.py)|[go](./src/1323-Maximum-69-Number/1323.go)|[js](./src/1323-Maximum-69-Number/1323.js)|[java](./src/1323-Maximum-69-Number/1323.java)|Easy|
|1324|[Print Words Vertically](https://leetcode.com/problems/print-words-vertically/)|c|[c++](./src/1324-Print-Words-Vertically/1324.cpp)|[python](./src/1324-Print-Words-Vertically/1324.py)|[go](./src/1324-Print-Words-Vertically/1324.go)|[js](./src/1324-Print-Words-Vertically/1324.js)|[java](./src/1324-Print-Words-Vertically/1324.java)|Medium|
30 changes: 30 additions & 0 deletions src/1324-Print-Words-Vertically/1324.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class Solution
{
public:
vector<string> printVertically(string s)
{
stringstream ss(s);
vector<string> strs;
string str;

while (ss >> str) strs.push_back(str);
int max_len = 0;
for (string& st : strs) max_len = max(max_len, (int)st.size());

vector<string> res(max_len);
for (int j = 0; j < max_len; j++)
{
for (string& st : strs)
{
if (st.size() > j) res[j] += st[j];
else res[j] += " ";
}
}

for (string& st : res)
{
while (!st.empty() && st.back() == ' ') st.pop_back();
}
return res;
}
};
29 changes: 29 additions & 0 deletions src/1324-Print-Words-Vertically/1324.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
func printVertically(s string) []string {
strs := strings.Split(s, " ")
max_len := 0
for _, st := range strs {
max_len = max(max_len, len(st))
}

res := []string{}
for j := 0; j < max_len; j++ {
t, t_len := []byte{}, 0
for _, st := range strs {
if len(st) > j {
t = append(t, st[j])
t_len = len(t)
} else {
t = append(t, ' ')
}
}
res = append(res, string(t[:t_len]))
}
return res
}

func max(a, b int) int {
if a > b {
return a
}
return b
}
23 changes: 23 additions & 0 deletions src/1324-Print-Words-Vertically/1324.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class Solution {
public List<String> printVertically(String s) {
String[] strs = s.split(" ");
int max_len = 0;
for (String st : strs) max_len = Math.max(max_len, st.length());

List<String> res = new ArrayList();
for (int j = 0; j < max_len; j++) {
StringBuilder t = new StringBuilder();
int t_len = 0;

for (String st : strs) {
if (st.length() > j) {
t.append(st.charAt(j));
t_len = t.length();
} else t.append(" ");
}
t.setLength(t_len);
res.add(t.toString());
}
return res;
}
}
19 changes: 19 additions & 0 deletions src/1324-Print-Words-Vertically/1324.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
var printVertically = function(s) {
let strs = s.split(" "), max_len = 0;
for (let st of strs) {
max_len = Math.max(max_len, st.length);
}

let res = [];
for (let j = 0; j < max_len; j++) {
let t = "", t_len = 0;
for (let st of strs) {
if (st.length > j) {
t += st[j];
t_len = t.length;
} else t += " ";
}
res.push(t.substring(0, t_len));
}
return res;
};
3 changes: 3 additions & 0 deletions src/1324-Print-Words-Vertically/1324.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Solution:
def printVertically(self, s: str) -> List[str]:
return [''.join(a).rstrip() for a in itertools.zip_longest(*s.split(), fillvalue=' ')]
8 changes: 4 additions & 4 deletions src/addProb.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import os, bisect

# 题目名称
name = "Maximum 69 Number"
ID = 1323
url = "https://leetcode.com/problems/maximum-69-number/"
difficult = "Easy"
name = "Print Words Vertically"
ID = 1324
url = "https://leetcode.com/problems/print-words-vertically/"
difficult = "Medium"
prog = ['c', 'cpp', 'py', 'go', 'js', 'java']


Expand Down

0 comments on commit f27854c

Please sign in to comment.