File tree Expand file tree Collapse file tree 4 files changed +98
-0
lines changed
lcci/01.04.Palindrome Permutation Expand file tree Collapse file tree 4 files changed +98
-0
lines changed Original file line number Diff line number Diff line change @@ -94,6 +94,42 @@ public:
94
94
};
95
95
```
96
96
97
+ ### **TypeScript**
98
+
99
+ ```ts
100
+ function canPermutePalindrome(s: string): boolean {
101
+ const set = new Set<string>();
102
+ for (const c of s) {
103
+ if (set.has(c)) {
104
+ set.delete(c);
105
+ } else {
106
+ set.add(c);
107
+ }
108
+ }
109
+ return set.size <= 1;
110
+ }
111
+ ```
112
+
113
+ ### ** Rust**
114
+
115
+ ``` rust
116
+ use std :: collections :: HashSet ;
117
+
118
+ impl Solution {
119
+ pub fn can_permute_palindrome (s : String ) -> bool {
120
+ let mut set = HashSet :: new ();
121
+ for c in s . chars () {
122
+ if set . contains (& c ) {
123
+ set . remove (& c );
124
+ } else {
125
+ set . insert (c );
126
+ }
127
+ }
128
+ set . len () <= 1
129
+ }
130
+ }
131
+ ```
132
+
97
133
### ** ...**
98
134
99
135
```
Original file line number Diff line number Diff line change @@ -83,6 +83,42 @@ public:
83
83
};
84
84
```
85
85
86
+ ### **TypeScript**
87
+
88
+ ```ts
89
+ function canPermutePalindrome(s: string): boolean {
90
+ const set = new Set<string>();
91
+ for (const c of s) {
92
+ if (set.has(c)) {
93
+ set.delete(c);
94
+ } else {
95
+ set.add(c);
96
+ }
97
+ }
98
+ return set.size <= 1;
99
+ }
100
+ ```
101
+
102
+ ### ** Rust**
103
+
104
+ ``` rust
105
+ use std :: collections :: HashSet ;
106
+
107
+ impl Solution {
108
+ pub fn can_permute_palindrome (s : String ) -> bool {
109
+ let mut set = HashSet :: new ();
110
+ for c in s . chars () {
111
+ if set . contains (& c ) {
112
+ set . remove (& c );
113
+ } else {
114
+ set . insert (c );
115
+ }
116
+ }
117
+ set . len () <= 1
118
+ }
119
+ }
120
+ ```
121
+
86
122
### ** ...**
87
123
88
124
```
Original file line number Diff line number Diff line change
1
+ use std:: collections:: HashSet ;
2
+
3
+ impl Solution {
4
+ pub fn can_permute_palindrome ( s : String ) -> bool {
5
+ let mut set = HashSet :: new ( ) ;
6
+ for c in s. chars ( ) {
7
+ if set. contains ( & c) {
8
+ set. remove ( & c) ;
9
+ } else {
10
+ set. insert ( c) ;
11
+ }
12
+ }
13
+ set. len ( ) <= 1
14
+ }
15
+ }
Original file line number Diff line number Diff line change
1
+ function canPermutePalindrome ( s : string ) : boolean {
2
+ const set = new Set < string > ( ) ;
3
+ for ( const c of s ) {
4
+ if ( set . has ( c ) ) {
5
+ set . delete ( c ) ;
6
+ } else {
7
+ set . add ( c ) ;
8
+ }
9
+ }
10
+ return set . size <= 1 ;
11
+ }
You can’t perform that action at this time.
0 commit comments