File tree 4 files changed +58
-6
lines changed
4 files changed +58
-6
lines changed Original file line number Diff line number Diff line change @@ -59,8 +59,8 @@ class Solution:
59
59
class Solution {
60
60
public boolean isUnique (String astr ) {
61
61
int bitmap = 0 ;
62
- for (int i = 0 , n = astr. length(); i < n; ++ i ) {
63
- int pos = astr . charAt(i) - ' a' ;
62
+ for (char c : astr. toCharArray() ) {
63
+ int pos = c - ' a' ;
64
64
if ((bitmap & (1 << pos)) != 0 ) {
65
65
return false ;
66
66
}
@@ -107,6 +107,25 @@ func isUnique(astr string) bool {
107
107
}
108
108
```
109
109
110
+ ### ** C++**
111
+
112
+ ``` cpp
113
+ class Solution {
114
+ public:
115
+ bool isUnique(string astr) {
116
+ int bitmap = 0;
117
+ for (char c : astr) {
118
+ int pos = c - 'a';
119
+ if ((bitmap & (1 << pos)) != 0) {
120
+ return false;
121
+ }
122
+ bitmap |= (1 << pos);
123
+ }
124
+ return true;
125
+ }
126
+ };
127
+ ```
128
+
110
129
### **...**
111
130
112
131
```
Original file line number Diff line number Diff line change @@ -56,8 +56,8 @@ class Solution:
56
56
class Solution {
57
57
public boolean isUnique (String astr ) {
58
58
int bitmap = 0 ;
59
- for (int i = 0 , n = astr. length(); i < n; ++ i ) {
60
- int pos = astr . charAt(i) - ' a' ;
59
+ for (char c : astr. toCharArray() ) {
60
+ int pos = c - ' a' ;
61
61
if ((bitmap & (1 << pos)) != 0 ) {
62
62
return false ;
63
63
}
@@ -104,6 +104,25 @@ func isUnique(astr string) bool {
104
104
}
105
105
```
106
106
107
+ ### ** C++**
108
+
109
+ ``` cpp
110
+ class Solution {
111
+ public:
112
+ bool isUnique(string astr) {
113
+ int bitmap = 0;
114
+ for (char c : astr) {
115
+ int pos = c - 'a';
116
+ if ((bitmap & (1 << pos)) != 0) {
117
+ return false;
118
+ }
119
+ bitmap |= (1 << pos);
120
+ }
121
+ return true;
122
+ }
123
+ };
124
+ ```
125
+
107
126
### **...**
108
127
109
128
```
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public:
3
+ bool isUnique (string astr) {
4
+ int bitmap = 0 ;
5
+ for (char c : astr) {
6
+ int pos = c - ' a' ;
7
+ if ((bitmap & (1 << pos)) != 0 ) {
8
+ return false ;
9
+ }
10
+ bitmap |= (1 << pos);
11
+ }
12
+ return true ;
13
+ }
14
+ };
Original file line number Diff line number Diff line change 1
1
class Solution {
2
2
public boolean isUnique (String astr ) {
3
3
int bitmap = 0 ;
4
- for (int i = 0 , n = astr .length (); i < n ; ++ i ) {
5
- int pos = astr . charAt ( i ) - 'a' ;
4
+ for (char c : astr .toCharArray () ) {
5
+ int pos = c - 'a' ;
6
6
if ((bitmap & (1 << pos )) != 0 ) {
7
7
return false ;
8
8
}
You can’t perform that action at this time.
0 commit comments