Python

문제 Implement strStr(). Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. Example 1: Input: haystack = "hello", needle = "ll" Output: 2Example 2: Input: haystack = "aaaaa", needle = "bba" Output: -1Clarification: What should we return when needle is an empty string? This is a great question to ask during an interview. For the purpose of this ..
문제 Given an array nums and a value val, remove all instances of that value in-place and return the new length. Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory. The order of elements can be changed. It doesn't matter what you leave beyond the new length. Example 1: Given nums = [3,2,2,3], val = 3, Your function shoul..
문제 Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. An input string is valid if: Open brackets must be closed by the same type of brackets. Open brackets must be closed in the correct order. Note that an empty string is also considered valid. Example 1: Input: "()" Output: trueEx..
문제 Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward. Example 1: Input: 121 Output: trueExample 2: Input: -121 Output: false Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.Example 3: Input: 10 Output: false Explanation: Reads 01 from right to left. Therefore it..
문제 Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have exactly one solution, and you may not use the same element twice. Example: Given nums = [2, 7, 11, 15], target = 9, Because nums[0] + nums[1] = 2 + 7 = 9, return [0, 1].풀이 class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]..
문제 Write a function to find the longest common prefix string amongst an array of strings. If there is no common prefix, return an empty string "". Example 1: Input: ["flower","flow","flight"] Output: "fl"Example 2: Input: ["dog","racecar","car"] Output: "" Explanation: There is no common prefix among the input strings.Note: All given inputs are in lowercase letters a-z. 풀이 class Solution: def lo..
문제 Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Value I 1 V 5 X 10 L 50 C 100 D 500 M 1000For example, two is written as II in Roman numeral, just two one's added together. Twelve is written as, XII, which is simply X + II. The number twenty seven is written as XXVII, which is XX + V + II. Roman numerals are usually written largest to smallest fro..
· 기타
개요 화면보호기가 해제되지 않는 환경에서 실행한 프로그램의 모니터링 작업이 필요한 경우 화면보호기의 동작을 막기 위한 목적으로 작성한 코드입니다. 사전작업 ※ 작업은 윈도우즈 10에서 수행하였습니다. python 설치 (환경변수에 python을 추가하도록 설정) 입력장치(마우스/키보드) 제어를 위한 python모듈을 설치합니다. > pip install pyautogui 코드 #! python3 # mouseMove.py - move mouse cursor periodic. import time import pyautogui print('Press Ctrl-C to quit.') cnt = 0; try: while True: cnt += 1 pyautogui.typewrite('H', interval=2..
쓴웃음
'Python' 태그의 글 목록 (3 Page)