Leetcode 91: Decode Ways

91. Decode Ways Total Accepted: 90213 Total Submissions: 488867 Difficulty: Medium Contributors: Admin A message containing letters from A-Z is being encoded to numbers using the following mapping: ‘A’ -> 1 ‘B’ -> 2 … ‘Z’ -> 26 Given an encoded message containing digits, determine the total number of ways to decode it. For example,Given …

Leetcode 67: Add Binary

67. Add Binary Total Accepted: 108940 Total Submissions: 367877 Difficulty: Easy Contributors: Admin Given two binary strings, return their sum (also a binary string). For example,a = "11"b = "1"Return "100".   Code class Solution(object): def addBinary(self, a, b): “”” :type a: str :type b: str :rtype: str “”” if len(b) > len(a): a, b …

Leetcode 283: Move Zeroes

283. Move Zeroes Total Accepted: 127538 Total Submissions: 272915 Difficulty: Easy Contributors: Admin Given an array nums, write a function to move all 0‘s to the end of it while maintaining the relative order of the non-zero elements. For example, given nums = [0, 1, 0, 3, 12], after calling your function, nums should be …

Leetcode 398: Random Pick Index

398. Random Pick Index Total Accepted: 6047 Total Submissions: 16791 Difficulty: Medium Contributors: Admin Given an array of integers with possible duplicates, randomly output the index of a given target number. You can assume that the given target number must exist in the array. Note:The array size can be very large. Solution that uses too …

Leetcode 49: Group Anagrams

49. Group Anagrams Total Accepted: 98283 Total Submissions: 321031 Difficulty: Medium Contributors: Admin Given an array of strings, group anagrams together. For example, given: ["eat", "tea", "tan", "ate", "nat", "bat"], Return: [ [“ate”, “eat”,”tea”], [“nat”,”tan”], [“bat”] ] Note: All inputs will be in lower-case.   Code from collections import defaultdict class Solution(object): def groupAnagrams(self, strs): …

Leetcode 48: Rotate Image

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 …

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”, …

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”] …