leetcode [#383] | GCidea's blog

作者:JerryXia | 发表于 , 阅读 (19)
目录1. 题目2. 解决方案3. 注意事项
题目Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the ransom note can be constructed from the magazines ; otherwise, it will return false.
Each letter in the magazine string can only be used once in your ransom note.
Example:canConstruct(“a”, “b”) -> falsecanConstruct(“aa”, “ab”) -> falsecanConstruct(“aa”, “aab”) -> true
Note:You may assume that both strings contain only lowerc...阅读全文

leetcode [#374] | GCidea's blog

作者:JerryXia | 发表于 , 阅读 (15)
目录1. 题目2. 解决方案3. 注意事项
题目We are playing the Guess Game. The game is as follows:
I pick a number from 1 to n. You have to guess which number I picked.
Every time you guess wrong, I’ll tell you whether the number is higher or lower.
You call a pre-defined API guess(int num) which returns 3 possible results (-1, 1, or 0):
-1 : My number is lower 1 : My number is higher 0 : Congrats! You got it!
Example:n = 10, I pick 6.
Return 6.
解决方案123456789101112131415161718192021/* The guess API is defin...阅读全文

leetcode [#394] | GCidea's blog

作者:JerryXia | 发表于 , 阅读 (17)
目录1. 题目2. 解决方案3. 注意事项
题目Given an encoded string, return it’s decoded string.
The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note that k is guaranteed to be a positive integer.
You may assume that the input string is always valid; No extra white spaces, square brackets are well-formed, etc.
Furthermore, you may assume that the original data does not contain any digits and that digits are only for those repeat num...阅读全文

leetcode [#415] | GCidea's blog

作者:JerryXia | 发表于 , 阅读 (18)
目录1. 题目2. 解决方案3. 注意事项
题目Given two non-negative numbers num1 and num2 represented as string, return the sum of num1 and num2.
Note:
The length of both num1 and num2 is < 5100.Both num1 and num2 contains only digits 0-9.Both num1 and num2 does not contain any leading zero.You must not use any built-in BigInteger library or convert the inputs to integer directly.解决方案12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061public class Solut...阅读全文

leetcode [#400] | GCidea's blog

作者:JerryXia | 发表于 , 阅读 (15)
目录1. 题目2. 解决方案3. 注意事项
题目Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, …
Example1:Input:3
Output:3
Example2:Input:11
Output:0
Explanation:The 11th digit of the sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, … is a 0, which is part of the number 10.
Note:n is positive and will fit within the range of a 32-bit signed integer (n < 231).
解决方案123456789101112131415161718192021222324252627282930313233public class Solution {    public int findNthDigit(int n) ...阅读全文