This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
func longestCommonPrefix(strs []string) string { | |
// This loop iterates based on the length of the first string. | |
// If strs[0] is "", this loop will not execute, and the function | |
// will correctly return strs[0] ("") at the end. | |
for i := 0; i < len(strs[0]); i++ { | |
char := strs[0][i] | |
for j := 1; j < len(strs); j++ { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func twoSum(nums []int, target int) []int { | |
addends := []int{0, 0} | |
for i := 0; i < len(nums); i++ { | |
addends[0] = i | |
for j := i+1; j < len(nums); j++ { | |
if nums[i] + nums[j] == target { | |
addends[1] = j | |
return addends |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
Robust script to update Optional[X] type hints to X | None syntax, | |
with reliable file discovery, proper indentation handling, and comprehensive error checking. | |
""" | |
import ast | |
import logging | |
import re | |
import tokenize | |
from dataclasses import dataclass, field |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
Comprehensive script to update Optional[X] type hints to X | None syntax, | |
handling complex edge cases including string templates, code generation, | |
metaclasses, conditional types, and runtime type generation. | |
""" | |
import ast | |
import logging | |
import re | |
import tokenize |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
Script to update Optional[X] type hints to X | None syntax | |
""" | |
import re | |
from pathlib import Path | |
import logging | |
logging.basicConfig(level=logging.INFO) | |
logger = logging.getLogger(__name__) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
Script to update Optional[X] type hints to X | None syntax | |
""" | |
import re | |
from pathlib import Path | |
import logging | |
logging.basicConfig(level=logging.INFO) | |
logger = logging.getLogger(__name__) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
Script to update Optional[X] type hints to X | None syntax | |
""" | |
import re | |
from pathlib import Path | |
def replace_optional(match): | |
"""Handle nested Optional[] replacements""" | |
inner_type = match.group(1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
Script to update Optional[X] type hints to X | None syntax | |
""" | |
import re | |
from pathlib import Path | |
def update_type_hints(file_path: str) -> None: | |
with open(file_path, 'r') as f: | |
content = f.read() |