-
Notifications
You must be signed in to change notification settings - Fork 0
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
Labels
Comments
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
|
/*
* @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
No description provided.
The text was updated successfully, but these errors were encountered: