๐ก ์ง์ ํผ ์ฝ๋
class Solution {
public int solution(String ineq, String eq, int n, int m) {
int answer = 0;
if (ineq.equals(">") && eq.equals("=")){
if (n>=m) answer = 1;
else answer = 0;
}
else if (ineq.equals("<") && eq.equals("=")){
if (n<=m) answer = 1;
else answer = 0;
}
else if (ineq.equals(">") && eq.equals("!")){
if (n>m) answer = 1;
else answer = 0;
}
else if (ineq.equals("<") && eq.equals("!")){
if (n<m) answer = 1;
else answer = 0;
}
return answer;
}
}
์ฐจ๋ก์ฐจ๋ก ๋น๊ตํด์ฃผ๋ ๋ฐฉ์์ผ๋ก ์งํํ๋ค.
๐ฌstr.equals() - ๋ฌธ์์ด ๋น๊ต์ == ์ฐ์ฐ์๊ฐ ์๋ equals() ํจ์๋ฅผ ์ฌ์ฉํด์ผํ๋ค.
๐ก ์ข์ ์ฝ๋
class Solution {
public int solution(String ineq, String eq, int n, int m) {
boolean flag = false;
if (">".equals(ineq) && n > m)
flag = true;
if ("<".equals(ineq) && n < m)
flag = true;
if ("=".equals(eq) && n == m)
flag = true;
return flag ? 1 : 0;
}
}
๊ฐ๋จํ๊ฒ 3์ข ๋ฅ๋ก ๊ตฌ๋ถํ๋ค
ํด๋, ์์๋, ๊ฐ์ ๋
๊ทธ๋ฆฌ๊ณ ์ฐ์ฐ์์ ํด๋น ์์ด ๋ง๋์ง ํ์ธํ๊ณ ์ฐธ,๊ฑฐ์ง์ ๋ฐํํ๋ฉฐ
๋ง์ง๋ง์ผ๋ก flag ๊ฐ ์ฐธ์ด๋ฉด 1์ ๋ฐํ , 0์ ๋ฐํํ๋ ๊ฐ๋จํ๊ณ ๋ณด๊ธฐ ์ข์ ์ฝ๋์ด๋ค !!