Skip to content

Commit e9ea98e

Browse files
committed
added more solutions
1 parent ce7612b commit e9ea98e

11 files changed

+69
-0
lines changed

Bash/192-Word_Frequency.sh

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Read from the file words.txt and output the word frequency list to stdout.
2+
cat words.txt | tr -s ' ' '\n' | sort | uniq -c | sort -r | awk '{ print $2, $1 }'

Bash/193-Valid_Phone_Numbers.sh

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Read from the file file.txt and output all valid phone numbers to stdout.
2+
grep -e "^[0-9]\{3\}\-[0-9]\{3\}\-[0-9]\{4\}$" -e "^([0-9]\{3\}) [0-9]\{3\}\-[0-9]\{4\}$" file.txt

Bash/194-Transpose_Files.sh

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Read from the file file.txt and print its transposed content to stdout.
2+
awk '{for (i=1; i<=NF; i++) {if (NR==1) {arr[i]=$i} else {arr[i]=arr[i] " " $i}}} END {for (i=1; i<=NF; i++) {print arr[i]}}' file.txt

JS/2690-Infinite_Method_Object.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @return {Object}
3+
*/
4+
var createInfiniteObject = function() {
5+
return new Proxy({}, {
6+
get: function(target, propKey) {
7+
return function() {
8+
return String(propKey);
9+
};
10+
}
11+
});
12+
};
13+
14+
/**
15+
* const obj = createInfiniteObject();
16+
* obj['abc123'](); // "abc123"
17+
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* @param {...(null|boolean|number|string|Array|Object)} args
3+
* @return {number}
4+
*/
5+
var argumentsLength = function(...args) {
6+
return args.length
7+
};
8+
9+
10+
/**
11+
* argumentsLength(1, 2, 3); // 3
12+
*/

JS/2796-Repeat_String.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* @param {number} times
3+
* @return {string}
4+
*/
5+
String.prototype.replicate = function(times) {
6+
let repl = '';
7+
for (let i = 0; i < times; i++) repl += this;
8+
return repl;
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Solution:
2+
def removeVowels(self, S):
3+
return "".join(c for c in S if c not in "aeiou")
4+
5+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import pandas as pd
2+
3+
def selectFirstRows(employees: pd.DataFrame) -> pd.DataFrame:
4+
return employees.iloc[0:3]

Python3/2884-Modify_Columns.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import pandas as pd
2+
3+
def modifySalaryColumn(employees: pd.DataFrame) -> pd.DataFrame:
4+
employees['salary'] = employees['salary'].multiply(2)
5+
return employees
6+

Python3/3110-Score_Of_A_String.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Solution:
2+
def scoreOfString(self, s: str) -> int:
3+
score = 0
4+
for i in range(len(s) - 1):
5+
score += abs(ord(s[i]) - ord(s[i + 1]))
6+
return score

Python3/367-Valid_Perfect_Square.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import math
2+
class Solution:
3+
def isPerfectSquare(self, num: int) -> bool:
4+
return sqrt(num) == floor(sqrt(num))

0 commit comments

Comments
 (0)