Skip to content

Commit 7455b00

Browse files
committed
feat: add solutions to lc problems: No.709,1309
- No.0709.To Lower Case - No.1309.Decrypt String from Alphabet to Integer Mapping
1 parent c9b68d4 commit 7455b00

File tree

7 files changed

+190
-0
lines changed

7 files changed

+190
-0
lines changed

solution/0700-0799/0709.To Lower Case/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,30 @@ func toLowerCase(s string) string {
106106
}
107107
```
108108

109+
### **Rust**
110+
111+
```rust
112+
impl Solution {
113+
pub fn to_lower_case(s: String) -> String {
114+
s.to_ascii_lowercase()
115+
}
116+
}
117+
```
118+
119+
```rust
120+
impl Solution {
121+
pub fn to_lower_case(s: String) -> String {
122+
String::from_utf8(
123+
s.as_bytes()
124+
.iter()
125+
.map(|&c| c + if c >= b'A' && c <= b'Z' { 32 } else { 0 })
126+
.collect(),
127+
)
128+
.unwrap()
129+
}
130+
}
131+
```
132+
109133
### **...**
110134

111135
```

solution/0700-0799/0709.To Lower Case/README_EN.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,30 @@ func toLowerCase(s string) string {
9494
}
9595
```
9696

97+
### **Rust**
98+
99+
```rust
100+
impl Solution {
101+
pub fn to_lower_case(s: String) -> String {
102+
s.to_ascii_lowercase()
103+
}
104+
}
105+
```
106+
107+
```rust
108+
impl Solution {
109+
pub fn to_lower_case(s: String) -> String {
110+
String::from_utf8(
111+
s.as_bytes()
112+
.iter()
113+
.map(|&c| c + if c >= b'A' && c <= b'Z' { 32 } else { 0 })
114+
.collect(),
115+
)
116+
.unwrap()
117+
}
118+
}
119+
```
120+
97121
### **...**
98122

99123
```
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
impl Solution {
2+
pub fn to_lower_case(s: String) -> String {
3+
String::from_utf8(
4+
s.as_bytes()
5+
.iter()
6+
.map(|&c| c + if c >= b'A' && c <= b'Z' { 32 } else { 0 })
7+
.collect(),
8+
)
9+
.unwrap()
10+
}
11+
}

solution/1300-1399/1309.Decrypt String from Alphabet to Integer Mapping/README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,53 @@ class Solution {
109109
}
110110
```
111111

112+
### **TypeScript**
113+
114+
```ts
115+
function freqAlphabets(s: string): string {
116+
const n = s.length;
117+
const res = [];
118+
let i = 0;
119+
while (i < n) {
120+
let code: string;
121+
if (s[i + 2] === '#') {
122+
code = s.slice(i, i + 2);
123+
i += 3;
124+
} else {
125+
code = s[i];
126+
i += 1;
127+
}
128+
res.push(code);
129+
}
130+
return res.map(v => String.fromCharCode(96 + Number(v))).join('');
131+
}
132+
```
133+
134+
### **Rust**
135+
136+
```rust
137+
impl Solution {
138+
pub fn freq_alphabets(s: String) -> String {
139+
let s = s.as_bytes();
140+
let n = s.len();
141+
let mut res = String::new();
142+
let mut i = 0;
143+
while i < n {
144+
let code: u8;
145+
if s.get(i + 2).is_some() && s[i + 2] == b'#' {
146+
code = (s[i] - b'0') * 10 + s[i + 1];
147+
i += 3;
148+
} else {
149+
code = s[i];
150+
i += 1;
151+
}
152+
res.push(char::from(97 + code - b'1'));
153+
}
154+
res
155+
}
156+
}
157+
```
158+
112159
### **...**
113160

114161
```

solution/1300-1399/1309.Decrypt String from Alphabet to Integer Mapping/README_EN.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,53 @@ class Solution {
8989
}
9090
```
9191

92+
### **TypeScript**
93+
94+
```ts
95+
function freqAlphabets(s: string): string {
96+
const n = s.length;
97+
const res = [];
98+
let i = 0;
99+
while (i < n) {
100+
let code: string;
101+
if (s[i + 2] === '#') {
102+
code = s.slice(i, i + 2);
103+
i += 3;
104+
} else {
105+
code = s[i];
106+
i += 1;
107+
}
108+
res.push(code);
109+
}
110+
return res.map(v => String.fromCharCode(96 + Number(v))).join('');
111+
}
112+
```
113+
114+
### **Rust**
115+
116+
```rust
117+
impl Solution {
118+
pub fn freq_alphabets(s: String) -> String {
119+
let s = s.as_bytes();
120+
let n = s.len();
121+
let mut res = String::new();
122+
let mut i = 0;
123+
while i < n {
124+
let code: u8;
125+
if s.get(i + 2).is_some() && s[i + 2] == b'#' {
126+
code = (s[i] - b'0') * 10 + s[i + 1];
127+
i += 3;
128+
} else {
129+
code = s[i];
130+
i += 1;
131+
}
132+
res.push(char::from(97 + code - b'1'));
133+
}
134+
res
135+
}
136+
}
137+
```
138+
92139
### **...**
93140

94141
```
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
impl Solution {
2+
pub fn freq_alphabets(s: String) -> String {
3+
let s = s.as_bytes();
4+
let n = s.len();
5+
let mut res = String::new();
6+
let mut i = 0;
7+
while i < n {
8+
let code: u8;
9+
if s.get(i + 2).is_some() && s[i + 2] == b'#' {
10+
code = (s[i] - b'0') * 10 + s[i + 1];
11+
i += 3;
12+
} else {
13+
code = s[i];
14+
i += 1;
15+
}
16+
res.push(char::from(97 + code - b'1'));
17+
}
18+
res
19+
}
20+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function freqAlphabets(s: string): string {
2+
const n = s.length;
3+
const res = [];
4+
let i = 0;
5+
while (i < n) {
6+
let code: string;
7+
if (s[i + 2] === '#') {
8+
code = s.slice(i, i + 2);
9+
i += 3;
10+
} else {
11+
code = s[i];
12+
i += 1;
13+
}
14+
res.push(code);
15+
}
16+
return res.map(v => String.fromCharCode(96 + Number(v))).join('');
17+
}

0 commit comments

Comments
 (0)