본문 바로가기
반응형

python311

Regular expression practice Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.Note: For the purpose of this problem, we define empty string as valid palindrome.Example 1:Input: "A man, a plan, a canal: Panama" Output: true Example 2:Input: "race a car" Output: false I know the concept of regular expression, however, I barely use this concept when I develop. I think.. 2019. 1. 17.
Rotate Image (Rotate array values 90 degrees, clockwise) Example 1:Given input matrix = [ [1,2,3], [4,5,6], [7,8,9] ], rotate the input matrix in-place such that it becomes: [ [7,4,1], [8,5,2], [9,6,3] ] This problem is to rotate the array values by 90 degrees. There is a constraint for this question. * Do not assign 2D array My approach is as below1. Transpose the array2. Reverse the each row class Solution: def rotate(self, matrix): """ :type matrix.. 2019. 1. 16.
python count built-in function example Given a non-empty 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?Example 1:Input: [2,2,1] Output: 1 Example 2:Input: [4,1,2,1,2] Output: 4 Brute-force way => comparing every elements while loop. However, if we use count function we can solve this pro.. 2019. 1. 15.
Best time to buy and sell stock II (1-line python code) Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (i.e., buy one and sell one share of the stock multiple times).Note: You may not engage in multiple transactions at the same time (i.e., you must sell the stock before you buy again).Example 1:Input: [7,1,5,3,6,4].. 2019. 1. 15.
반응형