137. Single Number II Total Accepted: 100365 Total Submissions: 253451 Difficulty: Medium Contributors: Admin Given an array of integers, every element appears three times except for one. Find that single one. Note:Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory? Code class Solution(object): def singleNumber(self, nums): “”” …
Monthly Archives: October 2016
Leetcode 72: Edit Distance
72. Edit Distance Total Accepted: 71110 Total Submissions: 236049 Difficulty: Hard Contributors: Admin Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.) You have the following 3 operations permitted on a word: a) Insert a characterb) Delete a characterc) …
Leetcode 150: Evaluate Reverse Polish Notation
150. Evaluate Reverse Polish Notation Total Accepted: 76968 Total Submissions: 304324 Difficulty: Medium Contributors: Admin Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, *, /. Each operand may be an integer or another expression. Some examples: [“2”, “1”, “+”, “3”, “*”] -> ((2 + 1) * 3) …
Continue reading “Leetcode 150: Evaluate Reverse Polish Notation”
Leetcode 138: Copy List with Random Pointer
138. Copy List with Random Pointer Total Accepted: 81110 Total Submissions: 308920 Difficulty: Hard Contributors: Admin A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null. Return a deep copy of the list. Code # Definition for singly-linked list …
Continue reading “Leetcode 138: Copy List with Random Pointer”
Leetcode 136: Single Number
136. Single Number Total Accepted: 167202 Total Submissions: 320990 Difficulty: Easy Contributors: Admin Given an array of integers, every element appears twice except for one. Find that single one. Note:Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory? Code class Solution(object): def singleNumber(self, nums): “”” :type nums: …
Leetcode 76: Minimum Window Substring
76. Minimum Window Substring Total Accepted: 76479 Total Submissions: 332625 Difficulty: Hard Contributors: Admin Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n). For example,S = "ADOBECODEBANC"T = "ABC" Minimum window is "BANC". Note:If there is no such window …
Leetcode 278: First Bad Version
278. First Bad Version Total Accepted: 68418 Total Submissions: 286586 Difficulty: Easy Contributors: Admin You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the previous version, all the versions after a …
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 …