File tree Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Solution (object ):
2
+ def twoSumLessThanK (self , A , K ):
3
+ """
4
+ :type A: List[int]
5
+ :type K: int
6
+ :rtype: int
7
+ """
8
+ if len (A ) < 2 :
9
+ return - 1
10
+ tmp = []
11
+ for i in range (len (A )):
12
+ for j in range (i + 1 , len (A )):
13
+ tmp .append (A [i ] + A [j ])
14
+
15
+ tmp .sort ()
16
+ if tmp [0 ] > K :
17
+ return - 1
18
+ # print tmp
19
+ res = tmp [0 ]
20
+ for item in tmp :
21
+ if item < K and abs (item - K ) < abs (res - K ):
22
+ res = item
23
+ return res
Original file line number Diff line number Diff line change
1
+ class Solution (object ):
2
+ def numKLenSubstrNoRepeats (self , S , K ):
3
+ """
4
+ :type S: str
5
+ :type K: int
6
+ :rtype: int
7
+ """
8
+ if len (S ) < K :
9
+ return 0
10
+ res = 0
11
+ for i in range (len (S ) - K + 1 ):
12
+ # for j in range(i + K, len(S)):
13
+ tmp = S [i :i + K ]
14
+ if self .check (tmp ):
15
+ res += 1
16
+ return res
17
+
18
+
19
+ def check (self , string ):
20
+ # record = {}
21
+ from collections import Counter
22
+ record = Counter (string )
23
+ # print record
24
+ for key , val in record .items ():
25
+ if val > 1 :
26
+ return False
27
+ # print string
28
+ return True
You can’t perform that action at this time.
0 commit comments