728x90 반응형 programming60 [SWEA] 2805. 농작물 수확하기 [SWEA] 2805. 농작물 수확하기 SW Expert Academy SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요! swexpertacademy.com [입력] 가장 첫 줄에는 테스트 케이스의 개수 T가 주어지고, 그 아래로 각 테스트 케이스가 주어진다. 각 테스트 케이스에는 농장의 크기 N과 농장 내 농작물의 가치가 주어진다. [출력] 각 줄은 '#t'로 시작하고, 공백으로 농장의 규칙에 따라 얻을 수 있는 수익을 출력한다. (t는 테스트 케이스의 번호를 의미하며 1부터 시작한다.) [풀이] 우선 홀수크기의 배열에 마름모꼴을 선택하게 되는 규칙을 찾았다. 첫행은 가운데 열 한칸으로 시작하고 그 이후로 계속 가운데 열을 기준으로 두칸씩 더해진다. 그리고 가운데 행에 다다르면.. 2021. 8. 4. [leetcode] 283. Move Zeroes 배열의 0을 모두 뒤로 보내는 문제이다. class Solution { public void moveZeroes(int[] arr) { int n = arr.length; int idx = 0; for(int i = 0; i < n; i++) { if(arr[i] != 0) { arr[idx] = arr[i]; idx++; } } for(int i = idx; i < n; i++) { arr[idx] = 0; idx++; } } } 별도의 result배열을 만들어서 사용하면 더 수월하지만, 조건에 주어진 배열만을 활용하라고 했기 때문에 배열에서 0이 아닌것을 그 배열 그대로 앞에서부터 채워나간다. 그리고 나머지 남은 배열칸에 0을 넣는다. 그러면 초기 배열이 완전히 바뀐다. 2021. 6. 29. StringBuilder 메소드 (append/deleteCharAt/lastIndexOf/insert/setCharAt) sb.append("q"); 추가 sb.deleteCharAt(sb.lastIndexOf(",")); 마지막 , 제거 sb.insert(0, "a"); 맨앞에 a추가 sb.setCharAt(0, 'a'); 맨앞을 a로 변경 (char형이라 '써주기) 2021. 6. 29. [leetcode] 66. Plus One Plus One - 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 이 문제는 약간 어려웠다. 앞선 문제들과 똑같이 난이도는 Easy인데 처음에 아예 Integer.parseInt해서 변환 후 +1을 하고 다시 그걸 배열에 담아주었다. (배열에 담아줄때 % 10해줘서 나머지를 뒷배열부터 넣어주었다.) 그런데 이 방법이 계속 에러가 뜨는 것이다. int[] test = {9,8,7,6,5,4,3,2,1,0}; 이러한 배열을 넣어줬을 때 int의 32bit 범위가 넘.. 2021. 6. 22. [leetcode] 482. License Key Formatting License Key Formatting - 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 처음에 문제를 잘못 이해했다. input : "2-4A0r7-4k" , 4 일 경우 "24A0-R74K"이 나와야 하는데, 나는 첫번째 그룹을 제외하고 그 이후를 k로 묶으라는 말로 들었다. 그래서 "2-4A0R-74K"가 나와버렸다. class Solution { public String licenseKeyFormatting(String s, int k) { String.. 2021. 6. 22. [leetcode] 771. Jewels and Stones Jewels and Stones - 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 a가 stones에 몇개 있는지, A가 stones에 몇개 있는지 찾는 문제다. 대소문자를 다르게 취급해주기때문에 별로 어렵지 않다. 처음에 문제를 이해하기 약간 어려울 수 있다. class Solution { public int numJewelsInStones(String jewels, String stones) { int result = 0; String[] J = jewels.. 2021. 6. 21. [leetcode] 929. Unique Email Addresses Unique Email Addresses - 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 간단히 말하자면, 아이디의 .이 있어도 없어도 같은 아이디로 생각하고 +이후부터는 아이디를 무시하여 고유한 이메일의 종류 갯수를 출력하는 문제이다. class Solution { public int numUniqueEmails(String[] emails) { HashSet R = new HashSet(); for(int i = 0; i < emails.length; i+.. 2021. 6. 21. [안드로이드/Kotlin] 인스타그램 클론코딩 - 3 (게시물 좋아요, 팔로우) 좋아요는 한 번 누르면 누른 사람의 정보가 입력되어 그 정보가 있으면 좋아요가 취소되게 해야 한다. viewHolder.detailviewitem_favorite_imageview.setOnClickListener{ favoriteEvent(position) } fun favoriteEvent(position: Int){ var tsDoc = firestore?.collection("images")?.document(contentUidList[position]) firestore?.runTransaction{ transaction -> var contentDTO = transaction.get(tsDoc!!).toObject(ContentDTO::class.java) if(contentDTO!!.favo.. 2021. 5. 28. [안드로이드/Kotlin] 인스타그램 클론코딩 - 2 (게시물 업로드, 프로필사진 등록) 게시물 업로드하기 사진 업로드 방법은 두가지가 있다. 나는 첫번째 방법으로 했다. //방법1.구글 권장 fun contentUpload(){ var timestamp = SimpleDateFormat("yyyyMMdd_HHmmss").format(Date()) var imageFileName = "IMAGE_" + timestamp + "_.png" var storageRef = storage?.reference?.child("images")?.child(imageFileName) storageRef?.putFile(photoUri!!)?.continueWithTask{ task: Task -> return@continueWithTask storageRef.downloadUrl }?.addOnSucces.. 2021. 5. 27. 이전 1 2 3 4 5 6 7 다음 728x90 반응형