20. Valid Parentheses Easy 18.3K 1K Companies Given a string s 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. Every close bracket has a corresponding open bracket of the same type. Example 1: Input: s = "()" Output: true Example 2: Input: s = "()[]{}" Output: true Example 3: Input: s = "(]" Output: false Constraints: 1 <= s.length <= 10 4 s consists of parentheses only '()[]{}' . My code: class Solution: def isValid(self, s: str) -> bool: a='([{' b=')]}' c=[] for i in s: if i in a and s.count(i)!=s.count(b[a.find(i)]):#checks if no.of opening element==no of closing element print(i,b[...
Posts
Showing posts with the label Software First semester break
- Get link
- X
- Other Apps
File Handling Scenario Prof. Jekyll conducts classes with students and regularly makes notes in a text file. Each line of the file contains three elements: the student's first name, the student's last name, and the number of point the student received during certain classes. The elements are separated with white spaces. Each student may appear more than once inside Prof. Jekyll's file. The file may look as follows: John Smith 5 Anna Boleyn 4.5 John Smith 2 Anna Boleyn 11 Andrew Cox 1.5 samplefile.txt Your task is to write a program which: asks the user for Prof. Jekyll's file name; reads the file contents and counts the sum of the received points for each student; prints a simple (but sorted) report, just like this one: Andrew Cox 1.5 Anna Boleyn 15.5 John Smith 7.0 output Note: your program must be fully protected against all possible failures: the file's non-existence, the file's emptiness, or any input data failures; encountering any data error should ...