-
Notifications
You must be signed in to change notification settings - Fork 0
/
167 Two Sum II - Input Array Is Sorted.rtf
30 lines (29 loc) · 2.09 KB
/
167 Two Sum II - Input Array Is Sorted.rtf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
{\rtf1\ansi\ansicpg1252\cocoartf2706
\cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fnil\fcharset0 .SFNS-Regular_wdth_opsz120000_GRAD_wght1F40000;\f1\fnil\fcharset0 Menlo-Regular;}
{\colortbl;\red255\green255\blue255;\red29\green29\blue29;\red255\green255\blue255;\red0\green0\blue0;
\red0\green0\blue255;\red32\green108\blue135;\red101\green76\blue29;\red0\green0\blue109;\red19\green118\blue70;
\red157\green0\blue210;}
{\*\expandedcolortbl;;\cssrgb\c14902\c14902\c14902;\cssrgb\c100000\c100000\c100000;\cssrgb\c0\c0\c0;
\cssrgb\c0\c0\c100000;\cssrgb\c14902\c49804\c60000;\cssrgb\c47451\c36863\c14902;\cssrgb\c0\c6275\c50196;\cssrgb\c3529\c52549\c34510;
\cssrgb\c68627\c0\c85882;}
\margl1440\margr1440\vieww11520\viewh8400\viewkind0
\deftab720
\pard\pardeftab720\partightenfactor0
\f0\fs36 \cf2 \cb3 \expnd0\expndtw0\kerning0
\outl0\strokewidth0 \strokec2 167\'a0Two Sum II - Input Array Is Sorted
\f1\fs26 \cf0 \cb1 \strokec4 \
\pard\pardeftab720\partightenfactor0
\cf5 \cb3 \strokec5 class\cf0 \strokec4 \cf6 \strokec6 Solution\cf0 \strokec4 :\cb1 \
\pard\pardeftab720\partightenfactor0
\cf0 \cb3 \cf5 \strokec5 def\cf0 \strokec4 \cf7 \strokec7 twoSum\cf0 \strokec4 (\cf8 \strokec8 self\cf0 \strokec4 , \cf8 \strokec8 numbers\cf0 \strokec4 : List[\cf6 \strokec6 int\cf0 \strokec4 ], \cf8 \strokec8 target\cf0 \strokec4 : \cf6 \strokec6 int\cf0 \strokec4 ) -> List[\cf6 \strokec6 int\cf0 \strokec4 ]:\cb1 \
\cb3 l,r = \cf9 \strokec9 0\cf0 \strokec4 , \cf7 \strokec7 len\cf0 \strokec4 (numbers)-\cf9 \strokec9 1\cf0 \cb1 \strokec4 \
\
\cb3 \cf10 \strokec10 while\cf0 \strokec4 l < r:\cb1 \
\cb3 \cf10 \strokec10 if\cf0 \strokec4 numbers[l] + numbers[r] == target:\cb1 \
\cb3 \cf10 \strokec10 return\cf0 \strokec4 [l+\cf9 \strokec9 1\cf0 \strokec4 ,r+\cf9 \strokec9 1\cf0 \strokec4 ]\cb1 \
\cb3 \cf10 \strokec10 elif\cf0 \strokec4 numbers[l] +numbers[r] > target:\cb1 \
\cb3 r-=\cf9 \strokec9 1\cf0 \cb1 \strokec4 \
\cb3 \cf10 \strokec10 else\cf0 \strokec4 :\cb1 \
\cb3 l+=\cf9 \strokec9 1\cf0 \cb1 \strokec4 \
\cb3 \cb1 \
}