48. Rotate Image Total Accepted: 84852 Total Submissions: 232792 Difficulty: Medium Contributors: Admin You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). Follow up:Could you do this in-place? General Idea: You need to first flip matrix upside down. Then swap elements mirror to …
Author Archives: czxttkl
Leetcode 13: Roman to Integer
13. Roman to Integer Total Accepted: 111025 Total Submissions: 261201 Difficulty: Easy Contributors: Admin Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. Code class Solution(object): def romanToInt(self, s): “”” :type s: str :rtype: int “”” pre = 0 sum = 0 …
Leetcode 17: Letter Combinations of a Phone Number
17. Letter Combinations of a Phone Number Total Accepted: 104864 Total Submissions: 335917 Difficulty: Medium Contributors: Admin Given a digit string, return all possible letter combinations that the number could represent. A mapping of digit to letters (just like on the telephone buttons) is given below. Input:Digit string “23” Output: [“ad”, “ae”, “af”, “bd”, “be”, …
Continue reading “Leetcode 17: Letter Combinations of a Phone Number”
Leetcode 16: 3Sum Closest
https://leetcode.com/problems/3sum-closest/ 16. 3Sum Closest Total Accepted: 97996 Total Submissions: 324135 Difficulty: Medium Contributors: Admin Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactly one solution. …
Leetcode 12: Integer to Roman
12. Integer to Roman Total Accepted: 80645 Total Submissions: 192971 Difficulty: Medium Contributors: Admin Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999. Code class Solution(object): def intToRoman(self, num): “”” :type num: int :rtype: str “”” M = [“”, “M”, “MM”, “MMM”] …
Leetcode 11: Container With Most Water
11. Container With Most Water Total Accepted: 99353 Total Submissions: 277586 Difficulty: Medium Contributors: Admin Given n non-negative integers a1, a2, …, an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, …
Leetcode 125: Valid Palindrome
125. Valid Palindrome Total Accepted: 124387 Total Submissions: 499823 Difficulty: Easy Contributors: Admin Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For example,"A man, a plan, a canal: Panama" is a palindrome."race a car" is not a palindrome. Note:Have you consider that the string might be empty? …
Leetcode 131: Palindrome Partitioning
131. Palindrome Partitioning Total Accepted: 77657 Total Submissions: 260955 Difficulty: Medium Contributors: Admin Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. For example, given s = "aab",Return [ [“aa”,”b”], [“a”,”a”,”b”] ] Code class Solution(object): def partition(self, s): “”” …
Leetcode 118: Pascal’s Triangle
https://leetcode.com/problems/pascals-triangle/ 118. Pascal’s Triangle Total Accepted: 103611 Total Submissions: 290013 Difficulty: Easy Contributors: Admin Given numRows, generate the first numRows of Pascal’s triangle. For example, given numRows = 5,Return [ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ] Code class Solution(object): def generate(self, numRows): “”” :type numRows: int :rtype: List[List[int]] “”” if numRows == 0: return …
Leetcode 120: Triangle
120. Triangle Total Accepted: 84503 Total Submissions: 265352 Difficulty: Medium Contributors: Admin Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below. For example, given the following triangle [ [2], [3,4], [6,5,7], [4,1,8,3] ] The minimum path sum from top to …