[Leetcode] Sum of Digits of String After Convert

김주형·2024년 9월 3일
0
post-thumbnail

You are given a string s consisting of lowercase English letters, and an integer k.

First, convert s into an integer by replacing each letter with its position in the alphabet (i.e., replace 'a' with 1, 'b' with 2, ..., 'z' with 26). Then, transform the integer by replacing it with the sum of its digits. Repeat the transform operation k times in total.

For example, if s = "zbax" and k = 2, then the resulting integer would be 8 by the following operations:

Convert: "zbax" ➝ "(26)(2)(1)(24)" ➝ "262124" ➝ 262124
Transform #1: 262124 ➝ 2 + 6 + 2 + 1 + 2 + 4 ➝ 17
Transform #2: 17 ➝ 1 + 7 ➝ 8
Return the resulting integer after performing the operations described above.

Example 1:

Input: s = "iiii", k = 1
Output: 36
Explanation: The operations are as follows:

  • Convert: "iiii" ➝ "(9)(9)(9)(9)" ➝ "9999" ➝ 9999
  • Transform #1: 9999 ➝ 9 + 9 + 9 + 9 ➝ 36
    Thus the resulting integer is 36.
    Example 2:

Input: s = "leetcode", k = 2
Output: 6
Explanation: The operations are as follows:

  • Convert: "leetcode" ➝ "(12)(5)(5)(20)(3)(15)(4)(5)" ➝ "12552031545" ➝ 12552031545
  • Transform #1: 12552031545 ➝ 1 + 2 + 5 + 5 + 2 + 0 + 3 + 1 + 5 + 4 + 5 ➝ 33
  • Transform #2: 33 ➝ 3 + 3 ➝ 6
    Thus the resulting integer is 6.
    Example 3:

Input: s = "zbax", k = 2
Output: 8

Constraints:

1 <= s.length <= 100
1 <= k <= 10
s consists of lowercase English letters.


컨텍스트 이해

  • 문자열 변경 후 각 자리수들의 합을 전달해주는 프로그램

기능목록

나의 풀이

// 변경 후 문자열 숫자의 함
// 소문자로 구성된 문자열 s를 

class Solution {
    public int getLucky(String s, int k) {
        int lucky = 0;

        

        return lucky;
    }

    private int convert(String s) {
        int convert = 0;
        for (char index: s.toCharArray()) {
            convert += getNumber(index);
        }
    }

    private void getNumber(char index) {

    }
    
    릿코드를 못 풀었으니 TIL을 기록할게요
    private int transformFirst(int convert) {
        int transformFirst = 0;

        convert

        
    }

    private int transformSecond(int transformFirst) {
        return transformFirst % 10 + (transformFirst / n * 10)
    }
}

배운점

  • 시간을 엄청 들였는데 개발을 할 줄 모른다..
  • 로직 하나 제대로 못 짠다..

이유

  • 비효율의 숙달화
  • 관심의 방향이 다른 곳에 쏠리진 않았는지..
  • 개발만 할 수 있어야 하는데..ㅠㅠ 생계를 이유로 알바를 너무 하고 의지와 상관없이 다른 일들에도 너무 많이 휘둘렸다

개선 포인트

  • 시간관리 법을 배우기 위해 독서하기
    - 브레이킹 루틴, 일의격, 돈이란 무엇인가, 좋은 기업을 넘어 위대한 기업으로
  • 컨텍스트 공유를 꾸준히 연습하기 위해 매일 TIL 1개씩 관리하기
  • 리소스 관리를 위해 건강한 식단과 지출 내역 기록하고 모니터링 하기
  • 일단 시작한 것은 끝까지 매듭 잘 짓기
profile
요행없음

0개의 댓글