기본공부/알고리즘 (4) 썸네일형 리스트형 [Leetcode] JAVA - Final Value of Variable After Performing Operations (Easy) 문제) "--X","X--"는 -1, "++X","X++"는 +1을 한다. 방법) class Solution { public int finalValueAfterOperations(String[] operations) { int result=0; for(int i=0;i [Leetcode] JAVA - Concatenation of Array (Easy) 문제) 배열 값을 연결해서 출력해야한다. 방법) class Solution { public int[] getConcatenation(int[] nums) { int n = nums.length; int[] ans = new int[2 * n]; for (int i = 0; i < n; i++) { ans[i] = nums[i]; ans[i+n] = nums[i]; } return ans; } } nums의 길이의 2배인 ans배열을 생성하고, ans[i]와 ans[i+n]에 각각 nums[i]를 대입한다. [Leetcode] JAVA - Palindrome Number (Easy) 문제) 대칭수 또는 회문수는 순서대로 읽은 수와 거꾸로 읽은 수가 같은 수를 말한다. 방법) class Solution { public boolean isPalindrome(int x) { if(0 [Leetcode] JAVA - Two sum(Easy) 문제) 배열 nums에서 인덱스의 원소값과 인덱스+1의 원소값을 더했을 때 target 값과 같으면 해당 인덱스들을 반환한다. 방법 1) class Solution { public int[] twoSum(int[] nums, int target) { for(int i=0; i 이전 1 다음