Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2022-10-22 #85

Open
github-actions bot opened this issue Oct 21, 2022 · 2 comments
Open

2022-10-22 #85

github-actions bot opened this issue Oct 21, 2022 · 2 comments

Comments

@github-actions
Copy link

No description provided.

@gongpeione
Copy link
Contributor

168 Excel Sheet Column Title

/*
 * @lc app=leetcode id=168 lang=typescript
 *
 * [168] Excel Sheet Column Title
 */

// @lc code=start
function convertToTitle(columnNumber: number): string {
    const ans = [] as string[];
    const startNum = 'A'.charCodeAt(0);

    while (columnNumber) {
        // because A is start from 1, not 0
        const num = (columnNumber - 1) % 26;
        ans.unshift(
            String.fromCharCode(startNum + num)
        );

        columnNumber = ~~((columnNumber - 1) / 26);
    }

    return ans.join('');
};
// @lc code=end

Nickname: Geeku
From vscode-hzfe-algorithms

@Akiq2016
Copy link

Akiq2016 commented Nov 6, 2022

/*
 * @lc app=leetcode.cn id=424 lang=java
 *
 * [424] 替换后的最长重复字符
 */

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

// @lc code=start
class Solution {
    public int characterReplacement(String s, int k) {
        int l = 0;
        int r = 0;
        int maxLen = 0;
        Map dict = new HashMap();

        while (l <= r && r <= s.length() - 1) {
            if (l == r && r == 0) {
                dict.put(s.substring(0 , 1), 1);
            }
            int maxCount = 0;
            for (Object count : dict.values()) {
                maxCount = Math.max(maxCount, (int) count);
            }
            if (r - l + 1 - maxCount <= k) {
                maxLen = Math.max(maxLen,r - l + 1);
                r++;
                if (r > s.length() - 1) {
                    break;
                }
                String key = s.substring(r , r+1);
                int value = dict.get(key) != null ? (int) dict.get(key) : 0;
                dict.put(key, value + 1);
            } else {
                String key = s.substring(l , l+1);
                int value = dict.get(key) != null ? (int) dict.get(key) : 0;
                dict.put(key, value - 1);
                l++;
                if (l > s.length() - 1) {
                    break;
                }
            }
        }

        return maxLen;
    }
}
// @lc code=end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants