Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
title1번 회고
		int count = 0;
        int pivot = 0;
		// 배열의 인덱스 + 1 값과 배열의 값은 같다. 
        for (int index = 0; index < arr.length; index++) {
            if (arr[index] != index + 1) {
                for (int i = index + 1; i < arr.length ; i++) {
                    if (arr[i] == index + 1) {
                        pivot = i;
                        break;
                    }
                }
                int temp = arr[index];
                arr[index] = arr[pivot];
                arr[pivot] = temp;
                count++;
            }
        }

        return count;


2.fail

Code Block
String s = "kkkk";
        char[] chars = s.toCharArray();

        for (int i = 1; i < chars.length; i++) {

            Map<String, Integer> map = new HashMap<>();

            for (int j = 0; j <= chars.length - i; j++) {
                String key = s.substring(j, j + i);
                char[] chars1 = key.toCharArray();
                Arrays.sort(chars1);
                key = Arrays.toString(chars1);
                map.put(key, map.getOrDefault(key, 0) + 1);
            }

            for (final Map.Entry<String, Integer> stringIntegerEntry : map.entrySet()) {
                System.out.println(stringIntegerEntry.getKey() + " : " + stringIntegerEntry.getValue());
            }
        }



3.