본문 바로가기
반응형

<개인공부> - IT/[Python]38

What is the point of float("-inf"), float("inf") I simply copy and paste a post that was posted on stackoverflow. It acts as an unbounded upper value for comparison. This is useful for finding lowest values for something. for example, calculating path route costs when traversing trees.e.g. Finding the "cheapest" path in a list of options:>>> lowest_path_cost = float('inf') >>> # pretend that these were calculated using some worthwhile algorith.. 2019. 1. 22.
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.
반응형