File tree 2 files changed +46
-0
lines changed 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * ์๊ฐ ๋ณต์ก๋: O(n)
3
+ * - ๊ณต์ฐจ๊ฐ 1์ธ ๋ฑ์ฐจ์์ด, ๋ฑ์ฐจ์์ด์ ํฉ ๊ณต์ ํ์ฉํ์ฌ ๊ธฐ๋ ๊ฐ์ ๊ณ์ฐ -> O(1)
4
+ * - ์ฃผ์ด์ง ๋ฐฐ์ด์ ์ํํ๋ฉด์ ๊ฐ ์์์ ํฉ์ ๊ณ์ฐ -> O(n)
5
+ * - ๊ธฐ๋ ๊ฐ์์ ์ค์ ๊ฐ ์์์ ํฉ์ ๋นผ๋ฉด ์ ๋ต -> O(1)
6
+ *
7
+ * ๊ณต๊ฐ ๋ณต์ก๋: O(1)
8
+ *
9
+ */
10
+ class Solution {
11
+ public int missingNumber (int [] nums ) {
12
+ int len = nums .length ;
13
+ int expectedSum = len * (len + 1 ) / 2 ;
14
+ int actualSum = 0 ;
15
+
16
+ for (int num : nums ) {
17
+ actualSum += num ;
18
+ }
19
+
20
+ return expectedSum - actualSum ;
21
+ }
22
+ }
Original file line number Diff line number Diff line change
1
+ /**
2
+ * ์๊ฐ ๋ณต์ก๋: O(n)
3
+ * - ์ ๊ท์์ ํตํด Alphanumeric ๋ง ๋จ๊ธฐ๊ธฐ. -> O(n)
4
+ * - ์๋ฌธ์๋ก ๋ณํ -> O(n)
5
+ * - ํฌ ํฌ์ธํฐ๋ฅผ ์ด์ฉํ๊ธฐ ๋๋ฌธ์ -> O(n/2)
6
+ * ๊ณต๊ฐ ๋ณต์ก๋: O(n)
7
+ */
8
+ class Solution {
9
+ public boolean isPalindrome (String s ) {
10
+ s = s .replaceAll ("[^a-zA-Z0-9]" , "" ).toLowerCase ();
11
+
12
+ char [] c = s .toCharArray ();
13
+
14
+ int left = 0 ;
15
+ int right = c .length - 1 ;
16
+
17
+ while (left < right ) {
18
+ if (c [left ++] != c [right --]) {
19
+ return false ;
20
+ }
21
+ }
22
+ return true ;
23
+ }
24
+ }
You canโt perform that action at this time.
0 commit comments