leetcode
-
LeetCode - Maximum Depth of Binary Tree [Java]Algorithms/- LeetCode 2022. 2. 10. 22:30
문제 링크 : Maximum Depth of Binary Tree Maximum Depth of Binary Tree - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 정답(Solution) /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} * TreeNode(int val) { th..
-
LeetCode - Valid Parentheses [Java]Algorithms/- LeetCode 2022. 1. 31. 03:03
문제 링크 : Valid Parentheses Valid Parentheses - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 정답(Solution) import java.util.*; class Solution { public boolean isValid(String s) { /* (){}[] 열리고 같은걸로 닫혀야한다. 올바른 순서로 닫혀야한다. */ //Stack Stack st = new Stack(); Map map = new HashMap(); ma..
-
LeetCode - longest common prefix [Java]Algorithms/- LeetCode 2022. 1. 31. 01:56
문제 링크 : longest common prefix Longest Common Prefix - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 정답(Solution) class Solution { public String longestCommonPrefix(String[] strs) { /* 공통 prefix를 리턴 없으면 "" */ if(strs.length == 1){ return strs[0]; } for(String str:strs){ if("".equa..
-
LeetCode - Roman to Integer [Java}Algorithms/- LeetCode 2022. 1. 31. 01:44
문제 링크 : Roman to Integer Roman to Integer - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 정답(Solution) import java.util.*; class Solution { public int romanToInt(String s) { /* String arr 로 만들고 하나씩 빼면서 이후에 VX LC DM 이 오는지 체크하면서 교체 IV, IX, XL , XC, CD, CM */ Map romanMap = new Hash..
-
LeetCode - Palindrome Number [Java]Algorithms/- LeetCode 2022. 1. 31. 00:15
문제 링크 : Palindrome Number Palindrome Number - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 정답(Solution) class Solution { public boolean isPalindrome(int x) { //음수 if(x < 0){ return false; } //0 if(x == 0){ return true; } String xStr = String.valueOf(x); int xLength = xStr.length..