luliyucoordinate / leetcode Goto Github PK
View Code? Open in Web Editor NEWPlay Leetcode with different programming language
Play Leetcode with different programming language
class Solution:
def frequencySort(self, s):
"""
:type s: str
:rtype: str
"""
str_map = {}
for i in s:
str_map[i] = str_map.get(i, 0) + 1
return ''.join(sorted([i for i in s], key=lambda a: str_map[a], reverse=True))
上面代码对用例'accdsseess'会把d和a放错,改成下面就ok了
def frequencySort(self, s):
"""
:type s: str
:rtype: str
"""
str_map = {}
for i in s:
str_map[i] = str_map.get(i, 0) + 1
return ''.join(sorted(
[i for i in s], key=lambda a: str_map[a], reverse=False))[::-1]
大佬好,
看到csdn的博客过来的。
最后一种解法,核心点是判断是否会走到紫色点。
如果我没理解错的话,判断紫色点是用的这一行代码:
https://github.com/luliyucoordinate/Leetcode/blob/master/src/1197-Minimum-Knight-Moves/1197.py#L7
您能讲一讲这一行是什么意思吗,为啥这样写就能work?
多谢!
The line 25 is wrong for the index should be 2:
heapq.heappop(p)[2]
还是先AC了再提交代码吧!!!
应该是r = min才对
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.