-
-
Save yhuag/a9b2fc1956970a89441c6ebcf6dc33a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
input: 1.2, 3.4, 2.1, 5 | |
a: 1 2 3 4 5 | |
1 1 1 1 | |
1 2 3 4 5 | |
sum: 4 3 2 1 1 | |
max: 4 | |
a = [a, man, is, nice] | |
this_array.split(" ") | |
a | |
man | |
is | |
nice | |
while(l+a[i] <= max) | |
l += a[i] | |
words = "..." | |
max_len = 10 | |
i = max_len | |
pre_i = 0 | |
while(i<words.length){ | |
while (words[i] != ' ' && i >= 0) i-- | |
print(words[pre_i:i+1]) | |
pre_i = i | |
i += max_len | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def getTruth(val, count): | |
return min(int(val), count) | |
def iterate(input_array): | |
candidate_val = 0 | |
candidate_count = 0 | |
candidate_truth = getTruth(candidate_val, candidate_count) | |
getCount = dict() | |
for num in input_array: | |
# Compare with candidate by value | |
if num > candidate_truth: | |
if num not in getCount: | |
getCount[num] = 1 | |
else: | |
getCount[num] += 1 | |
# Compare with candidate by count | |
if getCount[num] >= candidate_count: | |
candidate_val = num | |
candidate_count = getCount[num] | |
return min(int(candidate_val), candidate_count) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment