일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- 알고리즘
- 정보처리기사
- 2020년 정보처리기사 4회
- sqldeveloper
- 스터디
- post
- 서평
- jsp
- 성적프로그램
- java
- 코드숨
- Python
- 2020년 일정
- 뇌정리
- git
- Jackson
- 미니프로젝트
- 책리뷰
- 필기
- Til
- LeetCode
- hackerrank
- 2020년 제4회 정보처리기사 필기 문제 분석
- 항해99
- If
- 함수형 코딩
- 주간회고
- 회고
- algorithms
- Real MySQL
- Today
- Total
목록LeetCode/Algorithms (14)
조컴퓨터

Interger.parseInt(a, 2); ...로 접근했다가 큰 수 때문에 튕겼다. ----------------------- int B = Integer.valueOf(b, 2); int C = A + B; while ( C > 0 ) { ans = ( C % 2) + ans; C /= 2; } ----------------------- class Solution { public String addBinary(String a, String b) { if( a == null || b == null ) { return a == null ? b: a; } int dec = 0; StringBuilder sb = new StringBuilder(); for( int i=a.length()-1, j=b.le..

1) digits[n]*1 + digits[n-1]*10 + digits[n-2]*100 + ... + digits[0]*10^n + 1 class Solution { public int[] plusOne(int[] digits) { int cnt = digits.length; int sum = 1; for( int i=cnt-1; i>=0; i--) { sum += digits[i]*10^{(cnt-1)-i}; } //charAt 으로 한 개씩 잘라서 배열하면 된다~~ } } 2) i) digits[n] = 1, 2, 3, ... , 8 일 때, digits[n] = 2, 3, 4, ... , 9 대입 ii) digits[n] = 9 일 때, digits[n] = 0 대입한 후 digits[n-1] =..

Input 된 글자의 끝으로 간다. for문을 돌려서 띄어쓰기가 없는 곳으로 간다. 띄어쓰기가 있을 때까지 count++ class Solution { public int lengthOfLastWord(String s) { int count = 0; for( int i=s.length()-1; i>=0; i-- ) { if( s.charAt(i)!=' ' ) { count++; } else if( count!=0 ) { break; } } return count; } }

카데인 알고리즘 class Solution { public int maxSubArray(int[] nums) { int maxSum = nums[0]; int curSum = nums[0]; for( int i=1; i maxSum ) { maxSum = curSum; } } return maxSum; } }

for문을 돌리려고 했으나 for문보다는 인덱스 값 두 개와 조건 하나를 두어서 인덱스 값을 대입해 비교하는 쪽이 식을 세우기에 훨씬 수월했다. class Solution { public int searchInsert(int[] nums, int target) { int i = 0; int idx = 0; while( i

? indexOf 로 바로 풀린다. class Solution { public int strStr(String haystack, String needle) { int num = haystack.indexOf(needle); if( needle.length() == 0 ) { num = 0; } return num; } } 너무 빨리 끝나서 다른 방향을 더 생각해 보았다. class Solution { public int strStr(String haystack, String needle) { if( needle.length() == 0 ) return 0; if( haystack.length() == 0 ) return -1; int i = 0, j = 0; while( i

배열로 해결함 class Solution { public int removeElement(int[] nums, int val) { int idx = 0; for( int i=0; i