-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #430 from taekwon-dev/main
[์คํ๊ถ] Week4 ๋ฌธ์ ํ์ด
- Loading branch information
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* ์๊ฐ ๋ณต์ก๋: O(n) | ||
* - ๊ณต์ฐจ๊ฐ 1์ธ ๋ฑ์ฐจ์์ด, ๋ฑ์ฐจ์์ด์ ํฉ ๊ณต์ ํ์ฉํ์ฌ ๊ธฐ๋ ๊ฐ์ ๊ณ์ฐ -> O(1) | ||
* - ์ฃผ์ด์ง ๋ฐฐ์ด์ ์ํํ๋ฉด์ ๊ฐ ์์์ ํฉ์ ๊ณ์ฐ -> O(n) | ||
* - ๊ธฐ๋ ๊ฐ์์ ์ค์ ๊ฐ ์์์ ํฉ์ ๋นผ๋ฉด ์ ๋ต -> O(1) | ||
* | ||
* ๊ณต๊ฐ ๋ณต์ก๋: O(1) | ||
* | ||
*/ | ||
class Solution { | ||
public int missingNumber(int[] nums) { | ||
int len = nums.length; | ||
int expectedSum = len * (len + 1) / 2; | ||
int actualSum = 0; | ||
|
||
for (int num: nums) { | ||
actualSum += num; | ||
} | ||
|
||
return expectedSum - actualSum; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* ์๊ฐ ๋ณต์ก๋: O(n) | ||
* - ์ ๊ท์์ ํตํด Alphanumeric ๋ง ๋จ๊ธฐ๊ธฐ. -> O(n) | ||
* - ์๋ฌธ์๋ก ๋ณํ -> O(n) | ||
* - ํฌ ํฌ์ธํฐ๋ฅผ ์ด์ฉํ๊ธฐ ๋๋ฌธ์ -> O(n/2) | ||
* ๊ณต๊ฐ ๋ณต์ก๋: O(n) | ||
*/ | ||
class Solution { | ||
public boolean isPalindrome(String s) { | ||
s = s.replaceAll("[^a-zA-Z0-9]", "").toLowerCase(); | ||
|
||
char[] c = s.toCharArray(); | ||
|
||
int left = 0; | ||
int right = c.length - 1; | ||
|
||
while (left < right) { | ||
if (c[left++] != c[right--]) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
} |