'Swift, Reverse only letters [closed]
I face the problem. When i try to reverse only letters in swift by using Two pointer pattern its actually doing swap instead. sample - Test 123 String 2 pointer output - gnir 123 tStseT expected output - tseT 123 gnirtS Can somebody advice the method, or give example of code pls.?
func reverseOnlyLetters(_ S: String) -> String {
var a = Array(S.unicodeScalars)
var i = 0
var j = a.count - 1
while i < j {
while !CharacterSet.letters.contains(a[i]) && i < j { i += 1 }
while !CharacterSet.letters.contains(a[j]) && i < j { j -= 1 }
let t = a[i]
a[i] = a[j]
a[j] = t
i += 1
j -= 1
}
var ret = ""
a.forEach({ ret += String(Character(UnicodeScalar($0))) })
return ret
}
Solution 1:[1]
create a subquery that sales shows totals by each week then subquery the results and find the max sales for a week. partition using row_number order by country_id, weekofyear, and sales occcurences descending.
select *
from
(
select country_id
,weekofyear
,occurrences
,row_number() over(partition by country_id order by country_id,occurrences desc) row_id
from
(
select distinct country_id,datepart(week,order_date) weekofyear, count(order_id) occurrences from orders
where order_date is not null
group by country_id,datepart(week,order_date)
)x
)y
where row_id=1
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
