-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeetCraftCodeC#.rtf
More file actions
44 lines (40 loc) · 4.66 KB
/
LeetCraftCodeC#.rtf
File metadata and controls
44 lines (40 loc) · 4.66 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
{\rtf1\ansi\ansicpg1252\cocoartf2706
\cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fswiss\fcharset0 Helvetica;\f1\fnil\fcharset0 HelveticaNeue-Bold;\f2\fmodern\fcharset0 Courier;
\f3\fmodern\fcharset0 Courier-Bold;\f4\fnil\fcharset0 Menlo-Regular;}
{\colortbl;\red255\green255\blue255;\red25\green25\blue25;\red255\green255\blue255;\red9\green9\blue9;
\red12\green99\blue153;\red0\green0\blue0;\red210\green50\blue85;\red135\green135\blue135;\red135\green91\blue44;
\red255\green255\blue255;\red133\green0\blue67;}
{\*\expandedcolortbl;;\cssrgb\c12941\c12941\c12941;\cssrgb\c100000\c100000\c100000;\csgenericrgb\c3529\c3529\c3529;
\cssrgb\c0\c46667\c66667;\cssrgb\c0\c0\c0;\cssrgb\c86667\c29020\c40784;\cssrgb\c60000\c60000\c60000;\cssrgb\c60392\c43137\c22745;
\cssrgb\c100000\c100000\c100000\c50196;\cssrgb\c60000\c0\c33333;}
\paperw11900\paperh16840\margl1440\margr1440\vieww15660\viewh8960\viewkind0
\pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\pardirnatural\partightenfactor0
\f0\fs28 \cf0 ********************************************************************************************************\
\f1\b\fs36 \cf2 \cb3 \expnd0\expndtw0\kerning0
49. Group Anagrams
\f0\b0\fs28 \cf0 \cb1 \kerning1\expnd0\expndtw0 \
********************************************************************************************************\
\pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\pardirnatural\partightenfactor0
\f2\fs26 \cf4 ************
\f3\b\fs36 C# :
\f2\b0\fs26
\f3\b\fs36 Method 3
\f2\b0\fs26 ************\
\
\pard\pardeftab720\partightenfactor0
\f4 \cf5 \expnd0\expndtw0\kerning0
\outl0\strokewidth0 \strokec5 public\cf0 \strokec6 \cf7 \strokec7 IList\cf8 \strokec8 <\cf7 \strokec7 IList\cf8 \strokec8 <\cf5 \strokec5 string\cf8 \strokec8 >>\cf0 \strokec6 \cf7 \strokec7 GroupAnagrams\cf8 \strokec8 (\cf5 \strokec5 string\cf8 \strokec8 []\cf0 \strokec6 strs\cf8 \strokec8 )\cf0 \strokec6 \cf8 \strokec8 \{\cf0 \strokec6 \
\cf5 \strokec5 if\cf0 \strokec6 \cf8 \strokec8 (\cf0 \strokec6 strs \cf9 \cb10 \strokec9 ==\cf0 \cb1 \strokec6 \cf5 \strokec5 null\cf0 \strokec6 \cf9 \cb10 \strokec9 ||\cf0 \cb1 \strokec6 strs\cf8 \strokec8 .\cf0 \strokec6 Length \cf9 \cb10 \strokec9 ==\cf0 \cb1 \strokec6 \cf11 \strokec11 0\cf8 \strokec8 )\cf0 \strokec6 \cf5 \strokec5 return\cf0 \strokec6 \cf5 \strokec5 new\cf0 \strokec6 \cf7 \strokec7 List\cf8 \strokec8 <\cf7 \strokec7 IList\cf8 \strokec8 <\cf5 \strokec5 string\cf8 \strokec8 >>();\cf0 \strokec6 \
\cf7 \strokec7 Dictionary\cf8 \strokec8 <\cf5 \strokec5 string\cf8 \strokec8 ,\cf7 \strokec7 List\cf8 \strokec8 <\cf5 \strokec5 string\cf8 \strokec8 >>\cf0 \strokec6 map \cf9 \cb10 \strokec9 =\cf0 \cb1 \strokec6 \cf5 \strokec5 new\cf0 \strokec6 \cf7 \strokec7 Dictionary\cf8 \strokec8 <\cf5 \strokec5 string\cf8 \strokec8 ,\cf7 \strokec7 List\cf8 \strokec8 <\cf5 \strokec5 string\cf8 \strokec8 >>();\cf0 \strokec6 \
\cf5 \strokec5 foreach\cf0 \strokec6 \cf8 \strokec8 (\cf5 \strokec5 string\cf0 \strokec6 s \cf5 \strokec5 in\cf0 \strokec6 strs\cf8 \strokec8 )\cf0 \strokec6 \cf8 \strokec8 \{\cf0 \strokec6 \
\cf5 \strokec5 char\cf8 \strokec8 []\cf0 \strokec6 ca \cf9 \cb10 \strokec9 =\cf0 \cb1 \strokec6 s\cf8 \strokec8 .\cf7 \strokec7 ToCharArray\cf8 \strokec8 ();\cf0 \strokec6 \
Array\cf8 \strokec8 .\cf7 \strokec7 Sort\cf8 \strokec8 (\cf0 \strokec6 ca\cf8 \strokec8 );\cf0 \strokec6 \
\cf5 \strokec5 string\cf0 \strokec6 keyStr \cf9 \cb10 \strokec9 =\cf0 \cb1 \strokec6 \cf5 \strokec5 new\cf0 \strokec6 \cf5 \strokec5 string\cf8 \strokec8 (\cf0 \strokec6 ca\cf8 \strokec8 );\cf0 \strokec6 \
\cf5 \strokec5 if\cf0 \strokec6 \cf8 \strokec8 (\cf9 \cb10 \strokec9 !\cf0 \cb1 \strokec6 map\cf8 \strokec8 .\cf7 \strokec7 ContainsKey\cf8 \strokec8 (\cf0 \strokec6 keyStr\cf8 \strokec8 ))\cf0 \strokec6 \cf8 \strokec8 \{\cf0 \strokec6 \
map\cf8 \strokec8 .\cf7 \strokec7 Add\cf8 \strokec8 (\cf0 \strokec6 keyStr\cf8 \strokec8 ,\cf0 \strokec6 \cf5 \strokec5 new\cf0 \strokec6 \cf7 \strokec7 List\cf8 \strokec8 <\cf5 \strokec5 string\cf8 \strokec8 >());\cf0 \strokec6 \
\cf8 \strokec8 \}\cf0 \strokec6 \
map\cf8 \strokec8 [\cf0 \strokec6 keyStr\cf8 \strokec8 ].\cf7 \strokec7 Add\cf8 \strokec8 (\cf0 \strokec6 s\cf8 \strokec8 );\cf0 \strokec6 \
\cf8 \strokec8 \}\cf0 \strokec6 \
\cf5 \strokec5 return\cf0 \strokec6 \cf5 \strokec5 new\cf0 \strokec6 \cf7 \strokec7 List\cf8 \strokec8 <\cf7 \strokec7 IList\cf8 \strokec8 <\cf5 \strokec5 string\cf8 \strokec8 >>(\cf0 \strokec6 map\cf8 \strokec8 .\cf0 \strokec6 Values\cf8 \strokec8 );\cf0 \strokec6 \
\cf8 \strokec8 \}\cf0 \strokec6 \
}