File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,8 @@ Step 2. Add the dependency
45
45
46
46
<summary >展开查看</summary >
47
47
48
+ https://leetcode.cn/problems/buddy-strings
49
+
48
50
https://leetcode.cn/problems/maximum-frequency-stack
49
51
50
52
https://leetcode.cn/problems/calculate-amount-paid-in-taxes
Original file line number Diff line number Diff line change
1
+ function buddyStrings ( A : string , B : string ) : boolean {
2
+ if ( A . length !== B . length || A . length + B . length <= 2 ) return false ;
3
+ if ( A === B ) {
4
+ return A . length > new Set ( A ) . size ;
5
+ }
6
+ const indexArr : number [ ] = [ ] ;
7
+ for ( let index = 0 ; index < A . length ; index ++ ) {
8
+ if ( A [ index ] !== B [ index ] ) {
9
+ indexArr . push ( index ) ;
10
+ }
11
+ }
12
+ if (
13
+ indexArr . length === 2 &&
14
+ A [ indexArr [ 0 ] ] === B [ indexArr [ 1 ] ] &&
15
+ B [ indexArr [ 0 ] ] === A [ indexArr [ 1 ] ]
16
+ ) {
17
+ return true ;
18
+ }
19
+ return false ;
20
+ }
21
+ export default buddyStrings ;
You can’t perform that action at this time.
0 commit comments