알고리즘
-
[leetcode] Max Consecutive Ones II알고리즘 2021. 9. 3. 12:10
https://leetcode.com/explore/featured/card/fun-with-arrays/523/conclusion/3230/ Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore. leetcode.com -> Fail 0과 1로 이루어진 특정 배열이 주어졌을때, 최대 한개의 0을 뒤짚을 수 있는 경우 연속되는 1의 개수가 가장 긴 값을 구하는 문제이다. 1. Bru..
-
[코딩인터뷰완전분석] 1.2_순열확인_풀이알고리즘 2021. 8. 24. 22:46
Q. 문자열 두 개가 주어졌을 때 이 둘이 서로 순열 관계에 있는지 확인하는 메서드를 작성하라. [체크] 대소문자는 구분해야 하는지 공백은 하나의 문자로 처리해야하는지 입력받은 두 문자열의 길이가 같은지 (널 체크도 하면 좋을것 같다.) 확인 후에 해당 문자열을 char배열로 만들어 정렬을 진행한다. 두 문자열을 모두 정렬했을시 값이 같으면 순열이므로 true 값을 반환하면 된다. public String sort (String s) { char[] content = s.toCharArray(); java.util.Arrays.sort(content); return new String(content); } public boolean permutation (String s, String t) { if (s..
-
[leetcode] Height Checker알고리즘 2021. 8. 24. 22:19
https://leetcode.com/explore/learn/card/fun-with-arrays/523/conclusion/3228/ Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore. leetcode.com 특정 배열이 주어졌을때 해당 배열을 오름차순으로 정렬할 시 몇개의 원소를 이동해야 하는가에 대한 문제이다. 일단, 입력받은 배열만큼의 동일한 배열을 새로 생성한 후 값을..
-
[코딩인터뷰완전분석] 1.1_중복이 없는가_풀이알고리즘 2021. 8. 24. 00:06
Q. 문자열이 주어졌을 때, 이 문자열에 같은 문자가 중복되어 등장하는지 확인하는 알고리즘을 작성하라 [체크] 문제를 풀기 전 ASCII 코드인지, 유니 코드인지 확인하자. 이 가정이 없다면, 배열의 크기를 늘려야한다. boolean isUnique (String str) { // ASCII 코드라 가정 1byte -> 2의8승, // 1비트는 값 표현에 쓰이지 않으므로 2의7승 최대 128개의 문자열이 들어온다. if (str.length() > 128) return false; boolean charSet = new boolean[128]; // charAt 함수를 통해 아스키 코드 값을 가져온 후 해당 아스키 코드값을 인덱스값으로 설정한다. // 그 후 해당 인덱스의 값을 true 로 설정. // ..
-
알고리즘 학습법알고리즘 2021. 8. 21. 11:24
1. 알고리즘 관련 이론을 이해하는 것이 중요하다. ㄴ 자료구조, 알고리즘, 개념, 수학이론 등 ㄴ 모르겠으면 해당 이론은 패스한 후 다른 이론을 공부하자. 2. 1문제당 2시간 정도 고민하는 시간을 갖자. ㄴ 2시간이 넘으면 포기하고 답을 찾아본 후 분석해보자. ㄴ 정답을 구하기 힘들다면, 커뮤니티를 활용하여 질문하는것도 방법이다. 3. 중요한 것은 충분히 고민해보고, 노력해보고 포기하는 것이다. ㄴ 답을 봤어도 풀었다고 생각하자. ㄴ 3일 1문제보다, 1일 3문제가 좋다. ㄴ 사용할 수 있 수 있는 라이브러리를 익혀두자. TIP. 많이 생각해보자. ㄴ 생각하는 과정을 배워서 스스로 그러한 생각을 해내는것이 중요하다. ㄴ 풀이에 대한 회고와 더 좋은 풀이방법을 찾아보자.
-
[LeetCode] Palindrome Number알고리즘 2021. 6. 22. 00:19
class Solution { public boolean isPalindrome(int x) { if (x =0; i--) { tmp += reverseX.charAt(i); } if (tmp.equals(strX)) { return true; } else { return false; } } } Palindrome Number - LeetCode Level up your coding skills and quickly land a job. This is ..