Power of Three
326. Power of Three
Solution 1
def isPowerOfThree(self, n):
"""
:type n: int
:rtype: bool
"""
if n <= 0:
return False
while n != 1:
if n % 3 != 0:
return False
n /= 3
return True
Solution 2 - Direct
def isPowerOfThree(self, n):
"""
:type n: int
:rtype: bool
"""
...
Lexicographically Smallest String After Applying Operations
1625. Lexicographically Smallest String After Applying Operations
You are given a string s of even length consisting of digits from 0 to 9, and two integers a and b.
You can apply either of the following two operations any number of times and in any order on s:
Add a to all odd indices of s (0-indexed). Digits post 9 are cycled back to 0. For ...
Best Team With No Conflicts
1626. Best Team With No Conflicts
You are the manager of a basketball team. For the upcoming tournament, you want to choose the team with the highest overall score. The score of the team is the sum of scores of all the players in the team.
However, the basketball team is not allowed to have conflicts. A conflict exists if a younger player has a...
Number of Sets of K Non-Overlapping Line Segments
1621. Number of Sets of K Non-Overlapping Line Segments
Given n points on a 1-D plane, where the ith point (from 0 to n-1) is at x = i, find the number of ways we can draw exactly k non-overlapping line segments such that each segment covers two or more points. The endpoints of each segment must have integral coordinates. The k line segments do ...
Fancy Sequence
1622. Fancy Sequence
Write an API that generates fancy sequences using the append, addAll, and multAll operations.
Implement the Fancy class:
Fancy() Initializes the object with an empty sequence.
void append(val) Appends an integer val to the end of the sequence.
void addAll(inc) Increments all existing values in the sequence by an integer i...
Coordinate With Maximum Network Quality
1620. Coordinate With Maximum Network Quality
You are given an array of network towers towers and an integer radius, where towers[i] = [xi, yi, qi] denotes the ith network tower with location (xi, yi) and quality factor qi. All the coordinates are integral coordinates on the X-Y plane, and the distance between two coordinates is the Euclidean di...
Remove Duplicates from Sorted Array
26. Remove Duplicates from Sorted Array
Solution
def removeDuplicates(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
pre_idx = 0
i = 1
while i < len(nums):
if nums[pre_idx] != nums[i]:
nums[pre_idx+1] = nums[i]
pre_idx += 1
i += 1
return pre_idx + 1
199 post articles, 25 pages.