【Lintcode】1485. Holy Grail spell
題目地址:
https://www.lintcode.com/problem/holy-grail-spell/description
給定一個只含英文字母的長 n n n的字串,返回大小寫都出現在其中的字典序最大的字母的大寫。題目保證解存在。
程式碼如下:
public class Solution {
/**
* @param Spell: The Spell
* @return: nothing
*/
public char holyGrailspell(String Spell) {
// Write your code here
boolean[] exista = new boolean[26], existA = new boolean[26];
for (int i = 0; i < Spell.length(); i++) {
char ch = Spell.charAt(i);
if ('a' <= ch && ch <= 'z') {
exista[ch - 'a'] = true;
} else {
existA[ch - 'A'] = true;
}
}
for (int i = 25; i >= 0; i--) {
if (exista[i] && existA[i]) {
return (char) ('A' + i);
}
}
return 0;
}
}
時間複雜度 O ( n ) O(n) O(n),空間 O ( 1 ) O(1) O(1)。
相關文章
- 3186. Maximum Total Damage With Spell CastingAST
- 【翻譯】GRAIL-手寫識別AI
- 語音識別2 -- Listen,Attend,and Spell (LAS)
- [LintCode] Daily TemperaturesAI
- [LintCode] Permutation in String
- [LintCode/LeetCode] Meeting RoomsLeetCodeOOM
- Lintcode 1263. Is Subsequence
- 【Lintcode】1189. Minesweeper
- 使用Grail進行大規模基礎設施管理AI
- Grail:Uber是如何管理大規模基礎設施的AI
- [LeetCode/LintCode] Largest Palindrome ProductLeetCode
- [LintCode/LeetCode] Contains Duplicate IIILeetCodeAI
- [LintCode] Check Full Binary Tree
- [LintCode/LeetCode] Remove Duplicate LettersLeetCodeREM
- [LintCode] 3Sum Smaller
- 【Lintcode】1615. The Result of Investment
- [LintCode] Binary Tree Level Order
- 【Lintcode】1736. Throw Garbage
- 【Lintcode】1665. Calculate Number
- 【Lintcode】1789. Distinguish UsernameNGUI
- 【Lintcode】1562. Number of RestaurantsREST
- 【Lintcode】576. Split Array
- 【Lintcode】1267. Lexicographical Numbers
- 【Lintcode】141. Sqrt(x)
- 【Lintcode】1415. Residual Product
- 【Lintcode】1230. Assign CookiesCookie
- 【Lintcode】1732. Snakes and Ladders
- 【Lintcode】1218. Number Complement
- 【Lintcode】1850. Pick ApplesAPP
- 【Lintcode】572. Music PairsAI
- 【Lintcode】318. Character Grid
- 【Lintcode】1891. Travel Plan
- [LintCode/LeetCode] Check Sum of K PrimesLeetCode
- [LintCode]NumberofIslands(島嶼個數)
- lintcode-514-柵欄染色
- 【Lintcode】1322. Product Equal B
- 【Lintcode】191. Maximum Product Subarray
- 【Lintcode】1786. Pub Sub Pattern